How To Add Virtual Network Interfaces To Debian/Ubuntu
Linux OSes make it insanely easy to bind multiple IP addresses to a single network interface. This is mainly useful for servers, where you often have one ethernet NIC with several several static IPs. In Debian-based OSes such as Ubuntu, all it takes is a changing one file and running one command to add a virtual interface:
First, run the following command to edit your network interfaces file. Feel free to use whatever editor you like… I just prefer nano:
sudo nano /etc/network/interfaces
The file on my virtual machine has a loopback address and a static IP already setup:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.1.1.100
gateway 10.1.1.1
netmask 255.255.255.0
broadcast 10.1.1.255
The easiest way to add a virtual interface is to copy the existing eth0 entry and change the interface name to eth0:0. Simply copy the entry and change the :0 to :1, :2, etc for each additional virtual interface. Then just change the IP address, and any of the other settings as needed:
auto eth0:0
iface eth0:0 inet static
address 10.1.1.101
gateway 10.1.1.1
netmask 255.255.255.0
broadcast 10.1.1.255
Once that is done you can either restart the server, or do it the linux way and just run this command for each interface you’ve added:
sudo ifup eth0:0
And that’s it, now you have multiple IPs. All that’s left is updating your server software to use both IPs, but that’s a topic for another day!
May 9, 2013 at 11:13 pm
Thanks very much for this simple tutorial