IP Aliasing : Assigning multiple IP addresses to single NIC
In this tutorial, we are going to learn to assign multiple IP addresses to a single NIC (Network Interface Card). This process of assigning multiple addresses to a single network interface is called IP aliasing.
Main advantage of using IP aliasing is that we don’t need multiple NICs to configure multiple IPs, hence saving us cost & configuration time. IP aliasing is most useful when using Apache IP based virtual hosting.
For this tutorial, we are going to use RHEL/CentOS 7 but the same process can also be used older versions of RHEL/CentOS, the only change being the name of the network interfaces other than that process is same.
Recommended Read: Top 7 commands for Linux Network Traffic Monitoring
Network interfaces files in RHEL/CentOS 7(on older versions as well) are located at ‘/etc/sysconfig/network-scripts’ & name of the interfaces are usually ‘ifcfg-en0sX’, where ‘X’ is the number of the interface. In my case, its ‘ifcfg-en0s0’. So we will be using the same for the purpose of this tutorial.
Using Network Manager
We will be using a tool called ‘nmtui’ for this method. NMTUI is command line based user interface for Network Manager & even works for the system that does not have GUI installed. Open terminal & enter the command,
We will get the following window,
Click on ‘Edit a connection’, & then select the network interface from the list of interfaces & press ENTER key,
Now we add the required number of IP address here & once done, we can click on ‘OK’ & then exit from the nmtui menu. Restart the NetworkManager service & we will have our IP aliasing ready.
For this method, we will manually create the necessary files needed. We will assign two different IPs in addition to the one we have already assigned to our interface ‘ifcfg-en0s0’. To create IP alias, we are going to use our default network interface file & then will create two copies of the file with names ‘ifcfg-en0s0:1‘ & ‘ifcfg-en0s0:2’
Now, let’s open primary network interface i.e. eth0, & see its content
We will now configure our other network interfaces, we only need to make changes for ‘DEVICE’ & ‘IPADDR’ for aliasing
& same is to be done for ‘ifcfg:eth0:2’
Save both files & restart the network service for changes to take effect.
To check IP addresses have bee assigned or not, run ‘ifconfig’
This completes our tutorial, if you are having any issues/comments, please do mention them in the comment box below.