Configuring virtual network interfaces in Linux - LinuxConfig.org

Did you know that you can assign more that one IP address to a single physical network interface? This technique is quite useful, for example when working with Apache and virtual hosts, as it allows you to access same Apache server by using two different IP addresses.


This is a companion discussion topic for the original entry at https://linuxconfig.org/configuring-virtual-network-interfaces-in-linux

Pablo Olivare

Hi, than for the article.
I have a question. I have two pc into de same lan.
10.10.10.10 and 10.10.10.11, the ping work fine togethers.
The I create a virtual eth0:0 11.11.11.10 and 11.11.11.11.
From PC One the ping to 11.11.11.10 work fine, this confirm success create the virtual interface.
But the ping from PC one to Two (11.11.11.11) doesnt work.
I loss some command? Thank you!!

koxmoz kox -> Pablo Olivare

Hi, the problem is that you cant have multiple host with the same ip,
real host1: 10.10.10.10
real host2: 10.10.10.11
virtual host1: 10.10.10.12
virtual host1: 10.10.10.13

I hope this can help you!

Side note:
Even if I write the new virtual interface at /etc/network/interface , the new interface does not persist after reboot. One way that worked for me was to uninstall network-manager.

sudo apt-get remove network-manager

I tried these instructions but for me they don’t work. don’t know what the problem is.
I’m running centos 7 on a raspberry pi3.
the virtual nic shows up as it should in the cli but I can’t ping anything on my lan and nothing on the lan can see the virtual nic I’ve created.
I called the virtual nic eth1 and I even created /etc/sysconfig/network-scripts/ifcfg-eth1 but still nothing.

Hi Anthony_Griffiths,

Welcome to our forums.

These instructions lead you to create a virtual dummy interface, which will not be seen outside of the operating system, so you will not be able to ping or connect to it anywhere but from inside the machine. That’s it’s purpose.

If you would like to have another IP address on your Raspberry you can communicate on, you can pull another on your existing physical nic with something like this:

$ sudo ip address add 192.168.1.125/24 dev eth0

Where 192.168.1.125 is the new IP address to add (make sure it’s not in use on your network), and eth0 is your physical NIC.

how to make the interface persist across reboots?

Hi KesunyianAyam,

Welcome to our forums.

If you use NetworkManager, you can add a new interface with nmtui, if not, you can add it to the /etc/network/interfaces file to keep it after reboots.