≡ Menu

HowTo Bind A Range Of IP’s in Debian / Ubuntu Linux

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 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
iface eth0:0 inet static
iface eth0:1 inet static
# 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
    up   ip addr add dev eth0 label eth0:0
    down ip addr del dev eth0 label eth0:0
    up   ip addr add dev eth0 label eth0:1
    down ip addr del 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
Sample outputs:

2: 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 brd scope global eth0
    inet scope global secondary eth0:0
    inet 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.

{ 12 comments… add one }

  • Stephen G May 30, 2007, 2:56 am

    Did you possibly make a type for the assignment?

    iface eth0:0 inet static

    should be (?):
    iface eth0:1 inet static

  • Darkall January 31, 2008, 4:09 am

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

  • redsonic June 9, 2008, 9:38 am


    Thank you a lot for this very nice howto.

    It was very helpful


  • Clint November 18, 2008, 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 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

  • nixCraft November 18, 2008, 7:30 am


    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 up; done


  • Joseph Bloe December 15, 2008, 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).

  • Gagan Brahmi May 16, 2009, 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?

    • Douglas June 12, 2011, 8:40 pm

      Not sure, but I just tried to add 5000 ipv6 ips to one interface, but got out of memory message after 4091 IPs

  • Jesse August 11, 2009, 1:15 am

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

  • conan June 2, 2010, 5:04 pm

    it seems that we can bind these ip to loopback, such as lo:1 lo:2 ?

  • Stephen April 8, 2011, 10:36 pm

    Okay, now I start to respect Fedora, RedHat and CentOS users and know why Debian or ubuntu sucks.
    ifcfg-eth0-range0 makes me envy

  • Patricia April 18, 2012, 6:44 am

    Juan, OHARA You’re both correct, my apsiogloe, it was a copypasta mistake on my part.Way to lazy to write 2 VHOST definitions so I just copy-pasted them and forgot to change the IP.

Leave a Comment

   Tagged with: , , , , , , , , , , , , , , , , ,