Setting Up Multiple IPs in Ubuntu

A standard network interface will look similar to the following in /etc/network/interfaces:

auto eth0
iface eth0 inet static
address 192.168.210.100
netmask 255.255.255.0
broadcast 192.168.210.255
gateway 192.168.210.1

Adding more IP addresses to those interfaces is as simple as creating an alias, done by duplicating the information for the initial interface and appending a colon followed by 0,1,2,3,etc according to how many aliases are needed, minus the gateway (the initial IPs gateway will be used):

auto eth0:0
iface eth0:0 inet static
address 192.168.210.101
netmask 255.255.255.0
broadcast 192.168.210.255

auto eth0:1
iface eth0:1 inet static
address 192.168.210.102
netmask 255.255.255.0
broadcast 192.168.210.255

When finished, run an ifconfig to verify that the new interfaces are up and then ping them from a client system.

  • Daenney

    There’s actually a much nicer way to do this in stead of duplicating interfaces all over the place (yes I know they are aliases but still).

    {{{
    auto eth0
    iface eth0 inet static
    address 192.168.210.100
    netmask 255.255.255.0
    broadcast 192.168.210.255
    gateway 192.168.210.1

    post-up ip addr add 192.168.210.102/32 dev eth0
    post-down ip addr del 192.168.210.102/32 dev eth0
    }}}

    I find this solution to be nicer as it doesn’t spawn additional interfaces. It has the disadvantage though that when using ifconfig you won’t see the additional IP’s, you’ll need to use {{{ip adds show}}}.