Network aliases (multiple IP addresses on one interface)It's not uncommon to run into a situation where a single network card (or simply a single network interface) needs to be assigned not one, but several IP addresses. In that case:
a) The primary address must always be assigned to interface ethX
b) Aliases (additional IP addresses) are assigned as ethX:Y, where Y is the alias number
For example, here's how we assign 2 more IP addresses to interface eth0:
# ifconfig eth0:1 inet 192.168.1.1 netmask 255.255.255.0
# ifconfig eth0:2 inet 192.168.2.1 netmask 255.255.255.0
Permanently, these interfaces are specified in the same file as all the others:
/etc/network/interfaces
Let's look at an example of such a file:
# 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
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.1
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.250
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 127.0.0.1
auto eth0:1
iface eth0:1 inet static
address 10.0.1.2
netmask 255.255.255.0
network 10.0.1.0
broadcast 10.0.1.255
auto eth0:2
iface eth0:2 inet static
address 10.100.10.3
netmask 255.255.255.0
network 10.100.10.0
broadcast 10.100.10.255
auto eth0:3
iface eth0:3 inet static
address 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
Here you can see that we specified one primary address and 3 aliases. Note that the gateway or dns-nameservers options cannot be applied to aliases.
Comments