Secondary IP (eth0:0) acts like main server IP
Solution 1:
From this document it appears that at least on CentOS 5 and I suspect above you can specify your routes by simply giving the correct iproute2 command arguments. (see the section on the IP Command Arguments Format
)
So instead of writing something like:
# route-eth0
ADDRESS0=0.0.0.0
NETMASK0=0.0.0.0
GATEWAY0=5.x.y.82
You could just have a file like this:
default via 5.x.y.82 dev eth0 src 5.x.x.251
I don't have a Redhat/Redhat derived box handy to test though.
Solution 2:
If the aliased IP addresses are not to be used as source addresses to non-local destinations, they should not be in the same subnet as the target of your default route. So change their netmasks to 255.255.255.255
and remove their broadcast addresses.
Solution 3:
First clear your 0.0.0.0 default gateway
route del -net default
Then declare default eth0 as default gateway device
route add -net default gw 5.x.y.82 dev eth0
It should work. Verify with
ip ro li
To save that as a rule try this messy thing:
Open /etc/sysconfig/network-scripts/network-functions
,
locate function add_default_route ()
and in that function, after the call to find_gateway_dev
add a line with GATEWAYDEV="eth0"
.
What happens is that the network-functions
script decides which device gets to be the default gateway. It examines the route to the gateway IP with ip get route to GATEWAY
and, using sed, matches the a device.
It seems that eth0:0 gets to be the one each time, so by hardcoding GATEWAYDEV="eth0"
you make sure that eth0 is always selected as the gateway device.
In older versions of RH you could just edit /etc/sysconfig/static-routes
and add default via 5.x.y.82 dev eth0
As a last resort /etc/rc.local
is always your friend!