1

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.

#/etc/network/interfaces
    auto eth0
    iface eth0 inet static
            address 92.xxx.xxx.92
            netmask 255.255.255.192
            network 92.xxx.xxx.64
            broadcast 93.xxx.xxx.127
            gateway 92.xxx.xxx.65

    auto eth0:1
    iface eth0:1 inet static
            address 108.xxx.xxx.146
            netmask 255.255.255.192
            gateway 108.xxx.xxx.129

#ip route show
    108.xxx.xxx.128/26 dev eth0  proto kernel  scope link  src 108.xxx.xxx.146
    92.xxx.xxx.64/26 dev eth0  proto kernel  scope link  src 92.xxx.xxx.92
    default via 108.xxx.xxx.129 dev eth0  src 108.xxx.xxx.146
    default via 92.xxx.xxx.65 dev eth0

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

5
  • Do you really have two default gateways? Or did you just blindly copy-pasta config?
    – womble
    Apr 29, 2012 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, 2012 at 1:34
  • Yes, and you almost certainly added it wrong.
    – womble
    Apr 29, 2012 at 2:57
  • Well, when I remove "gateway 108.xxx.xxx.129" then it works. I thought that's also required for incoming connections?
    – XDragonX
    Apr 29, 2012 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, 2012 at 9:42

2 Answers 2

3

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.

1

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.

1
  • 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, 2012 at 19:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .