How do I add a secondary IP to Linux? Print

  • additional IP, secondary IP, unmanaged, IP, server
  • 230

Adding a secondary IP address allows your server to respond to multiple IPs on the same network card. The method varies slightly depending on your Linux distribution and whether you’re using the old ifcfg system or the newer ip/nmcli tools.


Temporary Method (until reboot)

Use the ip command to add a secondary IP immediately:

ip addr add 192.168.1.50/24 dev eth0
  • 192.168.1.50/24 → the secondary IP with subnet mask

  • eth0 → your network interface name

This change lasts until the next reboot.


Persistent Method (AlmaLinux / CentOS / RHEL with ifcfg)

Create a new configuration file such as:

/etc/sysconfig/network-scripts/ifcfg-eth0:0

With content like:

DEVICE=eth0:0 BOOTPROTO=static ONBOOT=yes IPADDR=192.168.1.50 NETMASK=255.255.255.0

Then restart networking:

systemctl restart network

Persistent Method (with NetworkManager / nmcli)

nmcli connection modify eth0 +ipv4.addresses 192.168.1.50/24 nmcli connection up eth0

Verification

Check that the secondary IP is active:

ip addr show dev eth0

Tip: Always ensure your hosting provider or upstream network has routed the new IPs to your server, otherwise they won’t function correctly.


Was this answer helpful?

« Back