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.
Best Answer
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). Thegateway
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.