I've recently installed Debian Linux 4.0 on my server and Ubuntu Linux 7.04 on Laptop. I would love to have a multiple IP address that I can use for verity of purposes. I would like to bind 4 IP's to the 'eth0' device or NIC. How do I achieve this?
Let us assume that your eth0 IP address is 192.168.1.1. You need to create alias or binding using eth0:0, eth0:1...eth0:N devices. You need to add range of IP's in /etc/network/interfaces config file under Debian/Ubuntu Linux. First make a backup of existing file:
# cp /etc/network/interfaces /root/working.interfaces
Now open file using a text editor such as vi / vim, enter:
# vi /etc/network/interfaces
$ sudo vi /etc/network/interfaces
Append or modify file as follows:
auto eth0 auto eth0:0 auto eth0:1 iface eth0 inet static address 192.168.1.1 netmask 255.255.255.0 gateway 192.168.1.254 iface eth0:0 inet static address 192.168.1.2 netmask 255.255.255.0 gateway 192.168.1.254 iface eth0:1 inet static address 192.168.1.3 netmask 255.255.255.0 gateway 192.168.1.254 # add rest of alias / binds below
A Note About Configuration Using ip Command
The ifconfig command is being phased out and being replaced by the ip command. The newer ip command does not use the same concept of aliases or virtual interfaces and instead treats additional addresses as first class objects. The newer way to configure multiple addresses on one interface is to use the up and down mechanism to call ip at the correct times to add and remove these additional IP addresses. Sample This /etc/network/interfaces file which assigns two IP addresses to eth0 and assigns labels to them:
auto eth0 allow-hotplug eth0 iface eth0 inet static address 192.168.1.1 netmask 255.255.255.0 gateway 192.168.1.254 up ip addr add 192.168.1.2/24 dev eth0 label eth0:0 down ip addr del 192.168.1.2/24 dev eth0 label eth0:0 up ip addr add 192.168.1.3/24 dev eth0 label eth0:1 down ip addr del 192.168.1.3/24 dev eth0 label eth0:1
Save and close the file. Restart networking service under Debian / Ubuntu Linux, enter:
# /etc/init.d/networking restart
$ sudo /etc/init.d/networking restart
How Do I Verify New Settings?
To verify your new settings, type:
# ifconfig -a
# ip addr show eth0
mtu 1500 qdisc mq state UP qlen 1000 link/ether b8:ac:6f:65:31:e5 brd ff:ff:ff:ff:ff:ff inet 192.168.1.1/24 brd 192.168.1.255 scope global eth0 inet 192.168.1.2/24 scope global secondary eth0:0 inet 192.168.1.3/24 scope global secondary eth0:1 inet6 fe80::baac:6fff:fe65:31e5/64 scope link valid_lft forever preferred_lft forever
Page last updated at 5:30 PM, April 2, 2012.