Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On a debian squeeze server I got 2 IPs on eth0 (eth0 and eth0:1). When opening TCP connections the server uses the eth0:1 IP by default. However I want it to use the primary (eth0) IP because I want the other to be used for (listening) daemons only.

    auto eth0
    iface eth0 inet static

    auto eth0:1
    iface eth0:1 inet static

#ip route show dev eth0  proto kernel  scope link  src dev eth0  proto kernel  scope link  src
    default via dev eth0  src
    default via dev eth0

What can I do to make debian use the 92. IP for outgoing connections? The other one should still work of course.

share|improve this question
Do you really have two default gateways? Or did you just blindly copy-pasta config? – womble Apr 29 '12 at 0:29
copy-pasta config? I just added the eth0:1 part to /etc/network/interfaces. everything else was done by debian installation. – XDragonX Apr 29 '12 at 1:34
Yes, and you almost certainly added it wrong. – womble Apr 29 '12 at 2:57
Well, when I remove "gateway" then it works. I thought that's also required for incoming connections? – XDragonX Apr 29 '12 at 8:48
Guys, stop downvoting every question where someone did something wrong. This site is dedicated to help those who are mistaken! – pauska Apr 30 '12 at 9:42
up vote 3 down vote accepted

You should almost certainly only have one gateway parameter in your networking config (basically, if you don't know why you need two, you don't). The gateway parameter specifies the default gateway for your machine -- the router that traffic which doesn't have a more-specific route should be sent. On most networks, there's only one router that fits that criteria, even though you may have several other (more specific) routes for other networks.

share|improve this answer

If by some reasons you really need 2 different IP networks to be working at the same time, you should use ip rule on Linux.

Say, two IP networks «A» and «B» are on the same NIC. «A» is primary one, i. e., when ping'ing some hosts from the box, you'd like «A» IP params to be used, so you place only «A»'s default gateway into the (main) routing table. And if you need replies coming from «B» to use «B»'s default gateway, then you can manage it with:

  • ip rule add from B_Network/Mask lookup table B_table pref 20000
  • ip route add default via B_gw table B_table

B_table should be defined in /etc/iproute2/rt_tables first. See LARTC for details.

share|improve this answer
Don't forget, multiple networks per interface is going to be a typical occurence under IPv6 and not the "if by some reason" outlier that the tone of your answer implies. – Magellan May 13 '12 at 19:57

Your Answer


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.