This site is now 100% read-only, and retired.

XML logo

Netmasks for IP interface aliases
Posted by endecotp on Tue 10 Jul 2007 at 23:15
Tags: none.
My box has a single network interface and two IP addresses. It is currently working fine with just the first of them configured.

Now I think that I should be able to bring up the second one using an alias, something like this:

ifconfig eth0:0 netmask <something> x.y.z.2

but I'm having trouble with the netmask setting. The netmask that I've been told applies to the two (neighbouring) addresses is This is what the first interface is configured with. Trying to use the same netmask on the alias gives an error (below) - but I'm not sure that I should be using the same netmask for the alias anyway; one search result told me that the alias should always have the netmask I tried that, but I still get this same error:

# ifconfig eth0:0 netmask x.y.z.2
SIOCSIFNETMASK: Cannot assign requested address

Actually although that looks like an error, it seems that it does bring up the interface alias and it is pingable, but it gives it a netmask of, which looks very wrong.

Can anyone explain what needs to happen here, and how to achieve it?

One possible answer would be "just add another section to /etc/network/interfaces and ifup eth0:0". Maybe ifup can do all this automagically for me. But I hesitate to do that, because I don't have physical access to this machine. At the moment, if I accedentally "ifdown eth0" I can remotely power-cycle it. However, if I screw up editing /etc/network/interfaces then a power-cycle might not help. So I'm only going to touch that file when I'm really confident that I have it correct.

In fact that's an interesting thought: could /etc/network/interfaces, and other critical configuration files, be set up with known-good fallbacks, used a bit like those "screen mode changed, click here within 10 secs if you can read this." dialogs?


Comments on this Entry

Re: Netmasks for IP interface aliases
Posted by daemon (155.232.xx.xx) on Wed 11 Jul 2007 at 22:32
[ View Weblogs ]

I'll try and get in here before anyone else does:

Use iproute.

For this kind of job, using iproute really is much easier, so instead of:

ifconfig eth0:0 netmask x.y.z.2

you would use:

ip addr add x.y.z.2/27 dev eth0

which you can also stick in your /etc/network/interfaces with a post-up command...

[ Parent ]

Re: Netmasks for IP interface aliases
Posted by endecotp (86.6.xx.xx) on Wed 11 Jul 2007 at 22:58
[ View Weblogs ]
> ip addr add x.y.z.2/27 dev eth0

Thanks for the suggestion. I've tried it; it completes without error, and the new address pings, but ifconfig doesn't show a new alias. Hmm, there is obviously an extra level of magic going on here that I don't understand. Is this iproute stuff just an alternative to ifconfig talking to the same kernel features, or is it talking to a different bit of the kernel?

Considering the potential for screwups in this case I would really prefer a "safe" choice....

[ Parent ]

Re: Netmasks for IP interface aliases
Posted by daemon (155.232.xx.xx) on Thu 12 Jul 2007 at 17:49
[ View Weblogs ]

Ahh, that's because when you start using the iproute tools (well, the ip tool anyway), you won't want to use ifconfig anymore. For anything. ifconfig(1) is old, outdated, and deprecated ... or so I was told, and I've never looked back.

The command you're looking for is:

ip addr list

but a plain `ip a' will also do the trick as ip(1) tries to figure out what you want it to do, as long as the options/sub-commands aren't ambiguous. While the manpage for ip(1) is filled with plenty of (possibly) confusing EBNF syntax options, it does give you an idea of the huge breadth of what ip(1) is capable of -- it can handle all you NIC devices, interfaces, routes, tunnels, etc. etc. it really is pretty cool...


[ Parent ]