Add multiple IP addresses using NMCLI

Multiple IP addresses using NMCLI

In this article, we’ll show you how to quickly add multiple IP addresses using NMCLI, a powerful command-line tool for configuring network settings on RHEL8/9 or CentOS 8/9 OS, streamlining your network administration tasks.

Table of Contents

Introduction

NetworkManager Command Line Interface (NMCLI) is a tool that allows network administrators to configure network settings on Linux systems. It is a command-line interface for NetworkManager, a system service that manages network connections. NMCLI is one of the most popular features of Red Hat Enterprise Linux (RHEL) and CentOS operating systems. In this article, we will provide a step-by-step guide on how to add multiple IP addresses using NMCLI on RHEL8/9 or CentOS 8/9 OS.

Brief history of NMCLI

NMCLI was first introduced in NetworkManager version 0.8 in 2010. It was designed to provide a command-line interface for NetworkManager, which until then only had a graphical user interface. NMCLI was designed to simplify the configuration of network settings on Linux systems, especially for servers that do not have a graphical user interface.

What is NMCLI?

NMCLI is a command-line interface for NetworkManager, a system service that manages network connections. It allows network administrators to configure network settings such as IP addresses, DNS servers, and network routes from the command line.

Most popular features of NMCLI

NMCLI has several features that make it a popular tool for configuring network settings on Linux systems. These include:

  • Command-line interface: NMCLI provides a command-line interface that allows network administrators to configure network settings from the command line.

  • Scriptable: NMCLI is scriptable, which means that it can be used in scripts to automate network configuration tasks.

  • Supports both IPv4 and IPv6: NMCLI supports both IPv4 and IPv6 addresses, which allows network administrators to configure both types of addresses from the command line.

  • Supports multiple connections: NMCLI allows network administrators to configure multiple network connections, which can be useful in situations where a server has multiple network interfaces.

Add Multiple IPv4 addresses

To add multiple IPv4 addresses using NMCLI, follow these steps:

Step 1: Open a terminal window on your RHEL8/9 or CentOS 8/9 system.

Type the following command to list your network connections:

				
					$ nmcli connection show
NAME                UUID                                  TYPE      DEVICE  
Wired connection 1  4eb75804-f1a0-31ca-b05c-041707af0164  ethernet  enp10s0 
lo                  c59566a8-ffe0-48de-ac05-8ef8886cf50c  loopback  lo      
node-net            146502e0-06a9-4345-aef0-4d07da420a4e  ethernet  enp1s0  

				
			

Step 2: Identify the connection

For the purposes of this illustration, we will use the node-net connection (above). Also, we’ll use the NMCLI Interactive Connection Editor to make this change.

Type the following command to launch the NMCLI Interactive Connection Editor for node-net:

				
					$ sudo nmcli connection edit node-net

===| nmcli interactive connection editor |===

Editing existing '802-3-ethernet' connection: 'node-net'

Type 'help' or '?' for available commands.
Type 'print' to show all the connection properties.
Type 'describe [<setting>.<prop>]' for detailed property description.

You may edit the following settings: connection, 802-3-ethernet (ethernet), 802-1x, dcb, sriov, ethtool, match, ipv4, ipv6, hostname, tc, proxy
nmcli> 
				
			

Next, type the following command (at the nmcli> prompt) to display the current IPV4 address settings:

				
					nmcli> print ipv4.address
ipv4.addresses: (null)

				
			

Step 3: Assign IP Addresses

Currently, there are no IPv4 addresses set for node-net. Therefore, execute the set command to assign the following IPv4 addresses to node-net: 192.168.1.44/24, 192.168.4.4/24

				
					nmcli> set ipv4.address
Enter 'addresses' value: 192.168.4.4/24, 192.168.1.44/24
Do you also want to set 'ipv4.method' to 'manual'? [yes]: 

				
			

You might be prompted about the ipv4.method setting. Hit the [Enter] key  to accept the default manual setting and continue.

				
					nmcli>

				
			

Now, enter the print ipv4.address command again to check if the change was successful.

				
					nmcli> print ipv4.address
ipv4.addresses: 192.168.4.4/24, 192.168.1.44/24


				
			

Congrats! Now save and quit the editor.

				
					nmcli> save
Connection 'node-net' (146502e0-06a9-4345-aef0-4d07da420a4e) successfully updated.
nmcli> quit



				
			

Step 4: Verify Changes

Finally, verify both IP addresses are listed using the nmcli con show command:

				
					$ sudo nmcli con show node-net | grep addresses
802-3-ethernet.accept-all-mac-addresses:-1 (default)
ipv4.addresses:                         192.168.4.4/24, 192.168.1.44/24
ipv6.addresses:       



				
			

Add Multiple IPv6 Addresses

To add multiple IPv6 addresses using NMCLI, repeat steps 2-4 and simply replace ipv4 with ipv6.

				
					$ sudo nmcli connection edit node-net

===| nmcli interactive connection editor |===

Editing existing '802-3-ethernet' connection: 'node-net'

Type 'help' or '?' for available commands.
Type 'print' to show all the connection properties.
Type 'describe [<setting>.<prop>]' for detailed property description.

You may edit the following settings: connection, 802-3-ethernet (ethernet), 802-1x, dcb, sriov, ethtool, match, ipv4, ipv6, hostname, tc, proxy
nmcli> print ipv6.address
ipv6.addresses: (null)
nmcli> 

				
			

Assign IPv6 Addresses

Similarly, we’re adding two random IPv6 addresses: 2001:db8:1::10 and 2001:db8:1::11 using the set ipv6.address command:

				
					nmcli> set ipv6.address
Enter 'addresses' value: 2001:db8:1::10, 2001:db8:1::11
Do you also want to set 'ipv6.method' to 'manual'? [yes]: 
nmcli> save 
Connection 'node-net' (146502e0-06a9-4345-aef0-4d07da420a4e) successfully updated.
nmcli> quit

				
			

Verify Latest Changes

A quick status check reveals both IPv4 and IPv6 addresses were added successfully!

				
					$ sudo nmcli con show node-net | grep addresses
802-3-ethernet.accept-all-mac-addresses:-1 (default)
ipv4.addresses:                         192.168.4.4/24, 192.168.1.44/24
ipv6.addresses:                         2001:db8:1::10/128, 2001:db8:1::11/128


				
			

Also, just fyi, the nmcli connection modify can also be used to make an IP address change.

				
					$ sudo nmcli connection modify node-net ipv4.addresses <IP_ADDRESS>


				
			

Highlights & Review

In the above examples, we used the nmcli connection edit command to add additional IP addresses to a network connection. Let’s break down the options used in this command:

  • nmcli: This is the command used to invoke NMCLI.

  • connection: This option is used to specify that we want to modify a network connection.

  • modify: This option is used to specify that we want to modify an existing network connection.

  • <connection-name>: This is the name of the network connection we want to modify (in this case: node-net).

  • set ipv4.address: This option is used to add one or more IPv4 addresses to the network connection.

  • set ipv6.address: This option is used to add one or more IPv6 addresses to the network connection.

Conclusion

NMCLI is a powerful tool that allows network administrators to configure network settings on Linux systems from the command line. In this article, we provided a step-by-step guide on how to add multiple IP addresses using NMCLI on RHEL8/9 or CentOS 8/9 OS. We also broke down the options used in the nmcli connection edit command that was used in our examples.

By following the steps outlined in this article, you can easily add multiple IP addresses to your network connections using NMCLI.

Was this article helpful to you? If so, leave us a comment below. We’d love to hear from you!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *