IP Aliasing: Assigning multiple IPs to a single NIC
When using IP based hosting to create a website, we require multiple IPs to launch multiple websites on a single apache server. For every website, we will need an IP address assigned to a single NIC or we can use IP aliasing. IP aliasing refers to the process of assigning multiple IPs to single NIC which will help save the cost as we don’t need multiple NICs to assign multiple IPs.
Use cases of IP aliasing can be many, as mentioned above it can used for IP based hosting or we can assign multiple IPs on a single server with each IP having its own function like one IP can host a FTP server. Other can act as a samba or DHCP or DNS server.
Note:- We will be using Centos/RHEL 7 for this tutorial but same process can be used for older versions as well.
Configuring Network interface file
We will assign two different IPs in addition to the one we have already assigned to our interface ‘ifcfg-enOs3’. To create IP alias, create two copies of the network interface file located at ‘/etc/sysconfig/network-scripts’ with names ‘ifcfg-enOs3:1‘ & ‘ifcfg-enOs3:2’
$ cd /etc/sysconfig/network-scripts $ cp ifcfg-enOs3 ifcfg-enOs3:1 $ cp ifcfg-enOs3 ifcfg-enOs3:2 |
Open the primary interface file i.e.’ifcfg-enOs3’ & view its contents
$ vi ifcfg-enOs3
DEVICE=”enOs3″ |
We will now configure our other network interfaces, we need to make changes for ‘DEVICE’ & ‘IPADDR’ for aliasing
$ vi ifcfg-enOs3:1
DEVICE=”enOs3:1″ |
Similarly edit the file ‘ifcfg:enOs3:2’
$ vi ifcfg-enOs3:2
DEVICE=”enOs3:2″ |
Save both files & restart the network service for implementing changes made to network
$ systemctl restart network |
Once the service has been restarted, we can check IP addresses for the newly created Aliases by running,
$ ifconfig |
Similarly we can assign more than two IPs to our NIC.