Linux Virtual IP Addressing
Posted in Techno Stuffs on May 26th, 2006
There are times wherein you would want to have multiple IP addresses for a single machine but just don’t have the resources or a justified need to add additional network interfaces. Let’s say you just want to be able to configure an Apache Web Server and Mail Server (Sendmail, Postfix,etc.) to listen on separate IP addresses. You just then need to provide a virtual IP address to your existing network interface to be able to configure your web server and mail server to listen on differen IP addresses.
Here’s a simple way to do it. ![]()
In these examples, we are just going to use IP addresses in the reserved IP range 192.168.0.1. Reserved IP addresses simply means that these are not valid IP addresses in the Internet but rather reserved for use internally or in other words inside a LAN.
For a machine with just a single network interface you would have eth0 as your network interface number. So to add an additional IP or virtual IP for this network interface we just need to issue the command:
ifconfig eth0:0 192.168.10.2 netmask 255.255.255.0 up
Notice that we used eth0:0 as the network interface number for our virtual IP. You can actually use any number after eth0: such as eth0:1,eth0:2,etc. I usually start my virtual network interface number with 0 ( eth0:0 ) but you can start with 1 if you want to. It doesn’t really matter but you just have to make sure that your network interface number and virtual IP addresses are unique. Network problems would surely occur if your settings aren’t unique.
Another way of doing this is by creating a file named /etc/sysconfig/network-scripts/ifcfg-eth0:0 and adding these lines to the said file (this is on a RedHat/Fedora/CentOS Linux machine):
DEVICE=eth0:0
ONBOOT=yes
BOOTPROTO=static
BROADCAST=192.168.10.255
IPADDR=192.168.10.2
NETMASK=255.255.255.0
NETWORK=192.168.10.0
ONBOOT=yes
Then restart your network services by executing:
$> /etc/rc.d/init.d/network restart
This approach would then make sure that your virtual IP address would be configured even after a restart or reboot.
Well that’s it. You can now configure your services to listen to your new virtual IP addresses.
[tags] Virtual IP, Linux Virtual IP, Linux Networking, CentOS, Fedora, RedHat, Linux Virtual IP Addressing, IP Addressing, IP Address[/tags]
