Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a VPS that has been assigned three IP addresses. Let's say that these are 192.168.123.45/24, 192.168.225.98/23 and 192.168.225.99/23. (The actual addresses are globally routable, but that is irrelevant for the purposes of this question. The netmask lengths, however, are like that.) The two subnets have different gateways, each in the respective subnet (obviously).

Originally, only 192.168.123.45/24 was configured, through auto and inet stanzas in /etc/networking/interfaces specifying eth0.

Now I am trying to configure the other two IP addresses as well. The naïve approach of just adding auto eth0:1 and inet eth0:1 stanzas to interfaces netted me an error RTNETLINK answers: File exists - Failed to bring up eth0:1.. Googling suggested I should do ifconfig eth0 add ... followed by ifconfig eth0:1 netmask ... gw ..., but this feels fragile.

What is the proper way to, on Debian Wheezy, set up virtual interfaces (or even without virtual interfaces) for a single physical interface where the virtual interfaces are to be on different subnets?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

With modern Linux, an interface can have multiple addresses without creating virtual interfaces. To do this, you need to use the ip command. This is not directly supported by Debian's ifupdown, but you can use a post-up script.

You can place a script in /etc/network/if-up.d with something like the following:

ip addr add dev eth0 192.168.225.99/23
ip addr add dev eth0 192.168.225.98/23

You can also add routes to this script, but assigning multiple default gateways is not recommended.

share|improve this answer
    
This seems to have done the trick. I don't know how Debian-esque it is, but it is certainly close enough for me. Thank you! (The only real downside is that the IP addresses don't show up in ifconfig's output, but I guess that isn't all that much of a downside these days.) –  Michael Kjörling Nov 28 '13 at 20:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.