I have a server with 2 interfaces. eth0 is 100 times faster than eth1. Though for some reason, every reboot, the default interface is picked at random. To make things more annoying, they both use the same gateway, so selecting the default gateway won't work. How does linux pick the default interface, and how do I select the default one?
Here is my route -n
to help explain the situation a bit.
Destination Gateway Genmask Flags Metric Ref Use Iface
173.246.100.0 0.0.0.0 255.255.252.0 U 0 0 0 eth1
173.246.100.0 0.0.0.0 255.255.252.0 U 0 0 0 eth0
0.0.0.0 173.246.103.254 0.0.0.0 UG 0 0 0 eth1
0.0.0.0 173.246.103.254 0.0.0.0 UG 100 0 0 eth0
PS. This is a VPS, so my provider might also be at fault somewhere. Reason for the second interface is to have another IP for dns, because it only does DNS, its very slow.
EDIT: This is a Ubuntu 10.04 server
Use
ifmetric
to change the metric value of both interfaces. Increasing eth1 above eth0 will cause eth0 to be used for all connections. Solves the problem entirely.You should disable the second, slow interface and then add the secondary IP on to the primary. To do this edit your interfaces file with:
Once you've accessed the network file you'll probably be presented with something like the following:
Reconfigure it to look like this:
This will assign both IPs to the first NIC. Once you've done this save the file and run:
And the changes will be committed.
<-- EDIT -->
In my experience if it's on the same Virtual Switch it shouldn't matter, though hosted environments may lock it down further. It may be worth a try though, if it doesn't work you can ask your hosting company to change the virtual interface to something more capable.
<-- EDIT -->
Also, if your primary IP isn't currently serving DNS then why not use it for DNS too? You can host several different services on one IP as they use different ports.
You seem to have two interfaces in the same subnet, which is a bit weird. Linux (assuming you are using a Red Hat derivative) picks the default gateway by reading the GATEWAY value from
/etc/sysconfig/network
. This variable, however, holds an IP address as a gateway identifier, not an interface name. So, in your case, the one IP address can be the gateway for both interfaces, leading (I think) to some sort of race condition.I'm still not sure why you need the second interface. What will happen if you bring down the slow interface completely?