If you have only one Ethernet adapter on your machine with the IP address of 192.168.0.5/24, but you have a machine on that network segment with the IP address of 10.0.2.3/24, you are going to have a tough time communicating with the 10.0.2.3 machine because your only network connection is on a different subnet than 10.0.2.3. The only way to communicate with this machine is to set your IP address to a machine in the 10.0.2.0/24 network. However, this is usually not an option as your connectivity to the outside world would probably be lost.
The quickest and easiest way to resolve this is to use a virtual interface. A virtual interface (also called a virtual adapter) is something you create and for all intents and purposes is seen as a new physical network interface. A virtual interface uses the physical connectivity of an existing network interface (in this case eth0) to be able to send and receive data. This does not affect the working of the main interface address (192.168.0.5), and it enables you to send and receive network traffic to both subnets.
One of the most common reasons for using virtual interfaces is that you need your computer to receive network traffic on multiple addresses on the same subnet. For example, if you were testing a new mail infrastructure with a separate SMTP and IMAP server, you could set up a test infrastructure on one machine running both the SMTP and IMAP server, but have them listening on 192.168.0.8 and 192.168.0.9, respectively. Using a virtual interface, you can test the connectivity from a desktop machine, and it seems, as far as the client machine is concerned, that the SMTP and IMAP services are running on separate machines.
To configure a virtual interface using ifconfig, you use exactly the same syntax as you do when setting up the IP address of eth0, with a slight twist. When specifying the network adapter to attach the virtual IP address to, you need to specify it in the form of realnet-workadapter:virtualinterface. So, for your first virtual adapter connected to eth0, you use eth0:1 .
bible:~ # ifconfig eth0:1 192.168.0.9 up
When the interface has been configured, you can then use it as you would any other real network interface you have on your system.
i: You can add an additional IP address to an interface using the ip command with a command line such as: ip addr add 192.168.0.9/24 dev eth0.
Was this article helpful?