Expanding network functionality: Adding secondary IP addresses with nmcli in Linux

Linux admin @ Freshers.in

Configuring secondary IP addresses using nmcli (NetworkManager Command-Line Interface) is a common task in Linux when you want a single network interface to have multiple IP addresses. This can be useful for various scenarios, such as running multiple services on a single server with different IP addresses. In this detailed article, we’ll guide you through the process of adding secondary IP addresses using nmcli with a comprehensive explanation for each step.┬áIn this article, we’ve provided a detailed guide on how to add a secondary IP address to a network interface using nmcli in Linux. This allows you to extend the functionality of your network interface by assigning multiple IP addresses for various purposes, enhancing your server’s network capabilities.


Before you begin, make sure you have the following:

  • A Linux distribution that uses NetworkManager for network configuration (e.g., Ubuntu, Fedora, CentOS).
  • Administrative access to your server (e.g., root or sudo privileges).
  • Basic knowledge of the Linux command line.

Step 1: Identify Your Network Interface

First, identify the network interface to which you want to add a secondary IP address. You can use the ip a command to list all network interfaces. For example:

ip a

Take note of the interface name you want to work with. In this example, let’s assume it’s named ens0.

Step 2: Create a New Connection Profile

To add a secondary IP address, you need to create a new connection profile for the network interface. You can do this using nmcli:

sudo nmcli connection add type ethernet ifname ens0 con-name secondary-ip

type ethernet: Specifies the connection type as Ethernet.

ifname ens0: Specifies the interface name.

con-name secondary-ip: Assigns a connection name (you can choose any name).

Step 3: Configure the Secondary IP Address

Now, you need to configure the secondary IP address within the newly created connection profile. Use nmcli to modify the connection and add the IP address:

sudo nmcli connection modify secondary-ip ipv4.addresses

Replace with the secondary IP address and subnet mask in CIDR notation that you want to assign.

Step 4: Activate the Connection

Activate the new connection profile to apply the changes:

sudo nmcli connection up secondary-ip

Step 5: Verify the Configuration

You can verify that the secondary IP address has been added successfully using the ip a command:

ip a

You should see the secondary IP address listed under the network interface you configured.

Step 6: Making Changes Permanent (Optional)

By default, changes made using nmcli are not persistent across reboots. If you want to make the secondary IP address configuration permanent, follow these steps:

Open the connection profile file for editing. Use your preferred text editor; for example:

sudo nano /etc/NetworkManager/system-connections/secondary-ip

Locate the [ipv4] section and add or modify the addresses line with the secondary IP address and subnet mask:

addresses=; # Add your secondary IP here

Save the file and exit the text editor.

Reload NetworkManager to apply the changes:

sudo systemctl restart NetworkManager

Now, the secondary IP address configuration should persist across reboots.

Read more on Shell and Linux related articles

Author: user