Did you know you can assign multiple IP addresses to the same network interface? It is known as IP aliasing. It allows you to setup or host multiple websites as virtual hosts, on a single network interface. In this case, you need separate network adapter for each IP but you can create separate virtual interfaces on a single network card. You can use these steps on most RHEL, Fedora & CentOS distributions.
How to Assign Multiple IP Addresses to Single Network Interface
Here are the steps to assign multiple IP addresses to single network interface. We have default interface for Ethernet device, ifcfg-eth0. Its device network files are located at /etc/sysconfig/network-scripts/. You can view them using ls command.
# sudo ls -l /etc/sysconfig/network-scripts ifcfg-eth0 ifdown-isdn ifup-aliases ifup-plusb init.ipv6-global ifcfg-lo ifdown-post ifup-bnep ifup-post net.hotplug ifdown ifdown-ppp ifup-eth ifup-ppp network-functions ifdown-bnep ifdown-routes ifup-ippp ifup-routes network-functions-ipv6 ifdown-eth ifdown-sit ifup-ipv6 ifup-sit ifdown-ippp ifdown-tunnel ifup-isdn ifup-tunnel ifdown-ipv6 ifup ifup-plip ifup-wireless
Let us say we want to bind 3 addresses 184.108.40.206, 220.127.116.11, and 18.104.22.168 to NIC (IP address 22.214.171.124). Here is a summary of final configuration desired.
Adapter IP Address Type ------------------------------------------------- eth0 126.96.36.199 Primary eth0:0 188.8.131.52 Alias 1 eth0:1 184.108.40.206 Alias 2 eth0:2 220.127.116.11 Alias 3
So we will clone the ifcfg-eth0 into 3 copies, one for each alias, with the following command.
# cd /etc/sysconfig/network-scripts/ # cp ifcfg-eth0 ifcfg-eth0:0 # cp ifcfg-eth0 ifcfg-eth0:1 # cp ifcfg-eth0 ifcfg-eth0:2
Now open ifcfg-eth0 in a text editor.
# vi ifcfg-eth0 DEVICE="eth0" BOOTPROTO=static ONBOOT=yes TYPE="Ethernet" IPADDR=18.104.22.168 NETMASK=255.255.255.224 GATEWAY=172.16.16.100 HWADDR=00:0C:29:28:FD:4C
We need to replace DEVICE and IPADDR parameters in each of the newly created files with the device name and IP address of alias.
Finally, here is what each of the 3 new files will look like.
DEVICE="eth0:0" BOOTPROTO=static ONBOOT=yes TYPE="Ethernet" IPADDR=22.214.171.124 NETMASK=255.255.255.224 GATEWAY=172.16.16.100 HWADDR=00:0C:29:28:FD:4C
DEVICE="eth0:1" BOOTPROTO=static ONBOOT=yes TYPE="Ethernet" IPADDR=126.96.36.199 NETMASK=255.255.255.224 GATEWAY=172.16.16.100 HWADDR=00:0C:29:28:FD:4C
DEVICE="eth0:2" BOOTPROTO=static ONBOOT=yes TYPE="Ethernet" IPADDR=188.8.131.52 NETMASK=255.255.255.224 GATEWAY=172.16.16.100 HWADDR=00:0C:29:28:FD:4C
Once you have updated the above files, restart network service to apply changes.
# sudo /etc/init.d/network restart
You can verify the setup with ifconfig or ip command.
You may also ping each of the above 3 new IP address aliases with ping commands, from different machines.
ping 184.108.40.206 ping 220.127.116.11 ping 18.104.22.168
That’s it. Now you can use these IP aliases to host multiple websites & services on a single network interface.