How to bind a range of IP’s in Debian / Ubuntu Linux

by Vivek Gite · 8 comments

Q. 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 do that?

A.. 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 vi text editor:
#vi /etc/network/interfaces
OR
$ sudo vi /etc/network/interfaces
Modify as follows:

auto eth0
auto eth0:0
auto eth0:1

iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.248
gateway 192.168.1.254

iface eth0:0 inet static
address 192.168.1.2
netmask 255.255.255.248
gateway 192.168.1.254

iface eth0:1 inet static
address 192.168.1.3
netmask 255.255.255.248
gateway 192.168.1.254
# add rest of alias / binds below

Save and close the file.

Now restart networking, enter:
# /etc/init.d/networking restart
OR
$ sudo /etc/init.d/networking restart

Updated for accuracy.

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 8 comments… read them below or add one }

1 Stephen G 05.30.07 at 2:56 am

Did you possibly make a type for the 192.168.1.3 assignment?

shows:
iface eth0:0 inet static
address 192.168.1.3
netmask 255.255.255.248
gateway 192.168.1.254

should be (?):
iface eth0:1 inet static
address 192.168.1.3
netmask 255.255.255.248
gateway 192.168.1.254

2 Darkall 01.31.08 at 4:09 am

Yes, he meant to type iface eth0:1 instead of iface eth0:0 :) He typo’d

3 redsonic 06.09.08 at 9:38 am

Hi,

Thank you a lot for this very nice howto.

It was very helpful

:)

4 Clint 11.18.08 at 4:54 am

This posting title is a bit misleading, it doesn’t tell you how to setup a range, it tells you how to setup multiple ip addresses individually.

Is there any way to say bind all ip’s in a 192.168.1.0/24 range, starting with eth0:0 or some such? Something without having to have 4 lines per ip address.

In RedHat its a special file called ifcfg-eth0-range0 and has some special parameters but allows you to bind hundreds of ip addresses with just a few lines

5 vivek 11.18.08 at 7:30 am

Clint,

title is correct and this is the only way to add ranges. Redhat/centos has special file for this purpose. However, you can write a shell script to add IP in ranges. Try something as follows from /etc/rc.local:

for ip in {1..254}; do echo ifconfig eth0:${ip} 192.168.1.$ip netmask 255.255.255.248 up; done

HTH

6 Joseph Bloe 12.15.08 at 1:29 am

Actually, what you have described is how to create a virtual interface on a NIC. A side effect of doing this is an IP alias is also automatically created. These are not the same things.

As an aside, I have several servers with several aliased IP addresses on the NICs. There are NO virtual interfaces (e.g. eth0.2, eth1:3, etc).

7 Gagan Brahmi 05.16.09 at 1:26 pm

Hey Vivek,

I have a related question. Do you know what is the maximum limit of IP addresses a single NIC can have in linux?

8 Jesse 08.11.09 at 1:15 am

Umm… yeah, so why is the netmask 255.255.255.248 when the client IPs are .1-3 and the gateway is at .254? Would you not need a netmask of 255.255.255.0 to keep the client IP’s and gateway in the same subnet??

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All