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
orsudo /sbin/ifconfig eth0:0 192.168.186.142
To verify whether alias is enabled and running fine, just ping it as follows:ping 192.168.186.142
Permanent Settings
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
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
Save the /etc/network/interfaces file and restart the networking service as follows:sudo service networking restart
orsudo /etc/init.d/networking restart
To observe whether your new interface has been added or not, run the following command:ifconfig
Output: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.
Hey Mandar,
ReplyDeleteThanks for the How-To.
I want to connect to each of the aliases ip using ssh remotely.
I manage to connect only to the "original" ip and not the other ip's.
Any thoughts ?
Thanks again,
James
Thanks
ReplyDeletenice
ReplyDeleteHi, I tried same command in Ubuntu 16.04, but it changes the IP address of the current interface, I mean IP address of "eth0" changed instead of creating one more interface. Please help on this.
ReplyDelete(info:in my case interface name is not "eth0")
Hi I tried the same command in Ubuntu 16.04, but it is changing the IP
ReplyDeleteof eth0 interface instead of creating new interface.
(info in my case interface name is not eth0)