The process in which multiple addresses are created on a single network interface, is known as "IP Aliasing". IP Aliasing will be very much useful when you need multiple IP addresses to set up multiple virtual sites on Apache making the use of only one network adapter. The most important advantage of IP Aliasing is that you do not need one hardware per IP Address, rather you can generate a pool of virtual network interfaces (i.e. Aliases) on a single device.
In this article, we will learn how these aliases are created and how we can assign an IP address to each of them. This very very very simple.
Here we go!
Let us consider that we have an ethernet interface 'eth0' with an IP address 192.168.186.141 and we have to create an alias 'eth0:0' with an IP address 192.168.186.142 on eth0. To do this, just enter following command:
sudo ifconfig eth0:0 192.168.186.142
To verify whether alias is enabled and running fine, just ping it as follows:
sudo /sbin/ifconfig eth0:0 192.168.186.142
When you make all the above changes and if the system is restarted, then all the changes made by you will be lost, as they are saved in volatile memory of your system. So as to make those changes permanent, you will have to add them to the network configuration file which is located at /etc/network/interfaces.
Use your favorite text editor to open the file and add the following configuration to it.
sudo gedit /etc/network/interfaces
Save the /etc/network/interfaces file and restart the networking service as follows:
auto eth0:0 iface eth0:0 inet static name eth0 Alias address 192.168.186.142 netmask 255.255.255.0 broadcast 192.168.186.255 network 192.168.186.0
sudo service networking restart
To observe whether your new interface has been added or not, run the following command:
sudo /etc/init.d/networking restart
In the similar way, you may create some more aliases having names eth0:1, eth0:2 and so on up to eth0:254 assigning them with different IP addresses.