Centos - Setting up multiple IP addresses on one NIC

Setting multiple Static IP addresses on a single network interface is simple.
 
The steps to add additional IP's to one network card / interface in Centos are as follows:

1.) Login into the server as the root user
2.) Navigate to /etc/sysconfig/network-scripts directory
3.) Assuming that the network interface name is eth0, cp ifcfg-eth0 as ifcfg-eth0:1
4.) Edit the ifcfg-eth0:1 file and change the DEVICE parameter to DEVICE=eth0:1
5.) Change the other parameters in the NEW file such as IPADDR to the new IP address.
6.) Repeat this process for each additional IP but remember to change the interface name each time e.g. ifcfg-eth0:2

After adding your additional IP's restart the network service: service network restart

You can add as many as you want, such as eth0:1, eth0:2

In Red Hat based distros (CentOS, Fedora etc.), the interfaces are edited through the directory /etc/sysconfig/network-scritps.

Here we have multiple files, each pointing for a device. For instance, to have 4 additional IP’s on a single ethernet device (totaling 5 addresses) we should have 5 files as follows,

/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0:1
/etc/sysconfig/network-scripts/ifcfg-eth0:2

/etc/sysconfig/network-scripts/ifcfg-eth0:3
/etc/sysconfig/network-scripts/ifcfg-eth0:4
 

The main device file would be just a standard one, we don’t have to change anything with it.
On the other hand, the ifcfg-eth0:1 file should be similar to this,

NAME=””
BOOTPROTO=static
MACADDR=””
IPV6INIT=no
DEVICE=eth0:1
NETMASK=xxx.xxx.xxx.xxx
MTU=””
BROADCAST=xxx.xxx.xxx.xxx
ONPARENT=yes
IPADDR=xxx.xxx.xxx.xxx
NETWORK=xxx.xxx.xxx.xxx
IPV6INIT=yes
IPV6ADDR=2f00:7300:100::11
IPV6_DEFAULTGW=2f00:7300:100::1
ONBOOT=yes

This would suffice. Don’t forget to restart your network services after adding the lines (or files) to with your appropriate settings.

Add Feedback