Mar 30, 2011

Setting up multiple IP addresses on a single NIC (Linux)

Copied from: http://linuxhelp.blogspot.com/2005/05/setting-up-multiple-ip-addresses-on.html
(I just copy it in case it got lost)

In linux, you can bind multiple IP addresses on a single NIC. This is usually done in case you are using your linux machine as a web server and is hosting multiple domains and you want to bind each domain to a unique IP address. This is how it is done.

Let us assume that you already have a NIC which is bound with a static IP address. Then you will have a file called /etc/sysconfig/network-scripts/ifcfg-eth0 .My ifcfg-eth0 file has the following entries:


# File: ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.1
NETMASK=255.255.255.0
BROADCAST=192.168.0.255
NETWORK=192.168.0.0
HWADDR=00:80:48:34:C2:84


Now to bind another IP address to the same NIC, I create a copy of the above file ifcfg-eth0 and name it as ifcfg-eth0:1


cd /etc/sysconfig/networking-scripts
cp ifcfg-eth0 ifcfg-eth0:1


Now just change the values of the DEVICE and IPADDR in the file as follows:


# File: ifcfg-eth0:1
DEVICE=eth0:1
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.5
NETMASK=255.255.255.0
BROADCAST=192.168.0.255
NETWORK=192.168.0.0
HWADDR=00:80:48:34:C2:84


And lastly, restart the networking service. If you are using RedHat, then it is as simple as :



service network restart