Ubuntu Linux: Creating ethernet alias for eth0 network device

Posted on in Categories Howto, Networking, Ubuntu Linux last updated June 17, 2006

Q. I am using Ubuntu Linux and I would like to know how to create alias for eth0 so that I can have multiple IP address?

A. To create alias for eth0 use ifconfig command. It is use to configure a network interface and aliases.

Assuming that your eth0 IP is 192.168.1.10 and you would like to create an alias eth0:0 with IP 192.168.1.11. Type the following command:

sudo ifconfig eth0:0 192.168.1.11 up

OR

sudo /sbin/ifconfig eth0:0 192.168.1.11 up

Verify that alias is up and running using following two command(s):

/sbin/ifconfig
ping 192.168.1.11
ping your-getway-ip

Permanent configuration

Your ethernet configuration is located in a file called /etc/network/interfaces. If you reboot system you will lost your alias. To make it permanent you need to add it network configuration file:

gksudo gedit /etc/network/interfaces

OR

sudo vi /etc/network/interfaces

Append the following configuration:

auto eth0:0
iface eth0:0 inet static
name Ethernet alias LAN card
address 192.168.1.11
netmask 255.255.255.0
broadcast 192.168.1.255
network 192.168.1.0

Save the file and restart system or restart the network:

sudo /etc/init.d/networking restart

Please note that you can also use graphical tools located at System > Administration > Networking menu. Or use the following GUI tool to setup aliases, hostname, dns settings etc:

sudo network-admin

If you want more network aliases, use eth0:1, eth0:2, eth0:N (max upto 254).

See also:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 28 comments/add one below):

28 comment

    1. Hello,

      I’m having a strange problem when adding eth0:2 to /etc/network/interfaces, when I try and restart the networking service the machine tries to reload the configuration and gets stuck there, the only way to bring networking back is removing the eth0:2 instances from the file and restarting (service restart won’t work after this happens the first time)

      If I simply bring up eth0:2 temporarily it doesn’t give me any problems.

      Any ideas?

      Thanks!

  1. Hell there. I am a new Linux user, more specifically Ubuntu. I was confused what was meant be the following line – “name Ethernet alias LAN card”. Is this the physical device name or just eth0?

    Any help with this would be great thanks.

  2. That is exactly what I have in my file… including the auto eth0:0. However, it looks like the auto is not that automatic on a reboot. Have you had problems on a reboot? Wondering because I’ve seen many people running in the problem of the 2nd IP disappearing after the machine is restarted.

    Thank you, Alexis

  3. I have the same problem as Alexis Wike, Did anyone come up with a solution for this. After reboot the eth0:0 does not comeup. The auto eth0:0 line is there in the file but it seems that it does nothing. Thanks

  4. The reason you may be having problems w/ AUTO on an alias is that you are not allowed to use anything other than the default subnet for the ip range in question.

    (Example: 10.x.x.x uses a default subnet of 255.0.0.0) If you try to assign any other subnet mask to the aliased ip, it won’t let you, and will take down the interface instantly. (Also true if you use ifconfig to assign the netmask).

    Kind of ruins the point needing things like a server w/ several 10.x.x subnets, and forces one to use 192.168 addresses for 255.255.255.0.

    Which would be fine if one didn’t already have a complex subnetted 10.x.x.x set of ranges in place because 192.168 doesn’t have enough subnets.

    Really annoying that.

  5. This thread is a little stale I guess but it’s the closest I could find…

    For those having issues with their aliases not coming up automatically on reboot, I’ve discovered that if the “root” interface ethx with no alias is not brought up, the aliases do not get configured.

    I fixed this by adding this lone entry only to my /etc/network/interfaces :
    auto ethx

    This worked under Ubuntu 12.04 at least.

  6. How do I bind an entire /22 in Ubuntu 16 server?

    right now I have this in interfaces:

    auto eno1
    iface eno1 inet static
    address xxx.xxx.16.2
    netmask 255.255.252.0
    network xxx.xxx.16.0
    broadcast xxx.xxx.19.255
    gateway xxx.xxx.16.1
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers 8.8.8.8 8.8.4.4
    dns-search domain.com

    I need to bind the full /22. I can only ping the .2 right now.

Leave a Comment