• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Geek Diary

HowTos | Basics | Concepts

  • Solaris
    • Solaris 11
    • SVM
    • ZFS
    • Zones
    • LDOMs
    • Hardware
  • Linux
    • CentOS/RHEL 7
    • RHCSA notes
    • SuSE Linux Enterprise
    • Linux Services
  • VCS
    • VxVM
  • Interview Questions
  • oracle
    • ASM
    • mysql
    • RAC
    • oracle 12c
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Hadoop
    • Hortonworks HDP
      • HDPCA
    • Cloudera
      • CCA 131

CentOS / RHEL 6 : How to add/remove additional IP addresses to a network interface

By admin

There are two ways to add another IP address to an interface. The old way creates a new virtual interface named in the style of ethX:Y where X and Y are numbers, for instance, eth0:1. Each interface has one IP address. It appears in ifconfig output as an ordinary interface and in ip output with a label attached.

The new way adds a secondary address to the main interface. So, instead of having one interface per IP address, it is possible to add many addresses to the real interface. However, ifconfig tool is too old and can’t see the additional IP addresses, so in this case, the ip tool must be used instead. This is the preferred way nowadays.

Add/Remove additional IP manually

1. Use the ip command to display the current ip address configuration of the interface eth0 :

# ip addr show eth0  
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000  
    link/ether 52:54:00:71:98:9d brd ff:ff:ff:ff:ff:ff  
    inet 10.10.122.101/24 brd 10.10.122.255 scope global eth0  
    inet 10.10.122.12/24 scope global secondary eth0  
    inet 10.10.122.11/24 scope global secondary eth0  
    inet 10.10.122.13/24 scope global secondary eth0  
    inet6 fe80::5054:ff:fe71:989d/64 scope link  
       valid_lft forever preferred_lft forever

2. To delete an existing IP

# ip addr del 10.10.122.13/24 dev eth0
# ip addr show eth0  
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000  
    link/ether 52:54:00:71:98:9d brd ff:ff:ff:ff:ff:ff  
    inet 10.10.122.101/24 brd 10.10.122.255 scope global eth0  
    inet 10.10.122.12/24 scope global secondary eth0  
    inet 10.10.122.11/24 scope global secondary eth0  
    inet6 fe80::5054:ff:fe71:989d/64 scope link  
       valid_lft forever preferred_lft forever

3. To add an IP address:

# ip addr add 10.10.122.13/24 dev eth0
# ip addr show eth0  
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000  
    link/ether 52:54:00:71:98:9d brd ff:ff:ff:ff:ff:ff  
    inet 10.10.122.101/24 brd 10.10.122.255 scope global eth0  
    inet 10.10.122.12/24 scope global secondary eth0  
    inet 10.10.122.11/24 scope global secondary eth0  
    inet 10.10.122.13/24 scope global secondary eth0  
    inet6 fe80::5054:ff:fe71:989d/64 scope link  
       valid_lft forever preferred_lft forever
WARNING: The manual method of adding or removing IP address is not persistent and the changes will disappear after a reboot or network service restart

Add/Remove Additional IP persistently

To add or remove additional IP adresses and keep the configuration persistent, we need to Edit the corresponding /etc/sysconfig/network-scripts/ifcfg-eth[x] configuration file and add/remove as many additional IPADDR[n] and PREFIX[n] entries as additional IP addresses are required.

For example the following configuration file:

# cat /etc/sysconfig/network-scripts/ifcfg-eth1  
DEVICE=eth1  
BOOTPROTO=none  
NETMASK=255.255.255.0  
TYPE=Ethernet  
HWADDR=52:54:00:cc:de:0b  
IPADDR=10.10.100.101  
PREFIX=24  
IPADDR2=10.10.128.101  
PREFIX2=24  
IPADDR3=10.10.130.101  
PREFIX3=28

would give the following result:

# ip addr show eth1  
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000  
    link/ether 52:54:00:cc:de:0b brd ff:ff:ff:ff:ff:ff  
    inet 10.10.100.101/24 brd 10.10.100.255 scope global eth1  
    inet 10.10.128.101/24 brd 10.10.128.255 scope global eth1  
    inet 10.10.130.101/28 brd 10.10.130.111 scope global eth1  
    inet6 fe80::5054:ff:fecc:de0b/64 scope link  
       valid_lft forever preferred_lft forever

The following additional entries are possible:

IPADDR: the additional IP address.
PREFIX: the length in bits of the netmask for the additional IP address.
NETMASK: the explicit netmask value for the additional IP address.
BROADCAST: the broadcast address for the additional IP address. This directive is deprecated, as the value is calculated automatically with ipcalc.

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to Boot into Rescue Mode or Emergency Mode Through Systemd in CentOS/RHEL 7 and 8
  2. How to Configure Early-kdump Support Feature in CentOS/RHEL 8
  3. CentOS / RHEL 7 : How to follow the mount order in /etc/fstab
  4. CentOS / RHEL 4 : How to install and configure FTP server (vsftpd)
  5. RHEL 7 – RHCSA Notes – input / output redirection
  6. Understanding DNS zone files
  7. /var/cache/yum Constantly Filling Files System in CentOS/RHEL
  8. Understanding kdump Configuration file /etc/kdump.conf
  9. How to Verify a Lun is in Active/Optimized Mode when ALUA Is Configured on Storage
  10. What is the refid in ntpq -p output?

You May Also Like

Primary Sidebar

Recent Posts

  • “su: Authentication failure” – in Docker
  • How to Pause and Resume Docker Containers
  • How to find docker storage device and its size (device mapper storage driver)
  • Understanding “docker stats” Command Output
  • ‘docker images’ command error – “Permission Denied”
  • Archives
  • Contact Us
  • Copyright

© 2019 · The Geek Diary