Ever wondered how to set multiple IPs in a single network card? Here is the solution.
Multiple IP binded in a single network card allows you run different services in different IPs, for example you can run HTTP on one IP and SMTP on another IP or a private LAN using a local IP and the alias holding your Public IP. The major benifit here is that you do not need an additional physical adaptor, you can bind many virtual IPs to a single network card. Here I have explained the procedure for creating multiple IPs for RedHat based and Debian bases systems
Redhat based systems.
Let me assume that your NIC is bound with a static IP address. Go to the folder /etc/sysconfig/network-scripts/, there you will find your network configuration files.
# cd /etc/sysconfig/network-scripts/
Let me also guess that your machine has only one network card (can be onboard too!!!), then you will find a file ifcfg-eth0 in the folder. This file holds the IP information for the first nic. If your machine has more nics you will have ifcfg-eth1, ifcfg-eth2 and so on... Now open the ifcfg-eth0 file, you can view the network configuration as below:
# cat ./ifcfg-eth0# File: ifcfg-eth0
Now to bind another IP address to the same network card, you just have to copy the ifcfg-eth0 file to ifcfg-eth0:1.
# cp ./ifcfg-etho ./ifcfg-eth0:1
Now open the file in your favourite editor and change the values of 'DEVICE' and IP ADDR' parameters.
# vi ./ifcfg-eth0:1
Now you can restart your network.
# service network restart
yes you are done. Now you have two IPs in a single network card. You can check it using:
Or else try pinging to the new IP from any other machins in your network.. Voila,,,, isn't it????
You can add as many number of virtual IPs as you want by the same way, just go on as ifcfg-eth0:1, ifcfg_etho:2, and so on...
Debian based systems
In debian based systems the IP information is store in /etc/network/interfaces file. Open it.
# cat /etc/network/interfaces
iface lo inet loopback
iface eth0 inet static
Now add these lines to the file: (Remember to make changes to the IP as per your need!!!)
iface eth0:1 inet static
You can add as many virtual IPs as needed.
After entering the required details you should restart the network using:
# /etc/init.d/networking restart
Voila you are done. You got multiple IPs in debian based systems too!!!!!
With warm regards,