12

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

3
  • Interesting, as the ifconfig manpage states this at the section about "metric": This parameter sets the interface metric. It is not available under GNU/Linux.
    – wzzrd
    Jun 24, 2011 at 14:09
  • 1
    Glad you figured this out. If nobody else answered this and your edit represents the solution, you should add that below in an answer section of it's own then accept it as the correct answer (after the timeout). Please do not put answers in the question section.
    – Caleb
    Jun 24, 2011 at 19:05
  • @Caleb: I was still on the timeout, I've posted my anwser
    – user163365
    Jun 25, 2011 at 10:18

3 Answers 3

15

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.

1
  • 2
    Does this change the default gateway immediately or after rebooting? Aug 26, 2015 at 5:44
2

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:

sudo vi /etc/network/interfaces

Once you've accessed the network file you'll probably be presented with something like the following:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
    address 173.246.100.1
    network 173.246.100.0
    netmask 255.255.252.0
    broadcast 173.246.100.255
    gateway 173.246.103.254

auto eth1
iface eth0 inet static
    address 173.246.100.2
    network 173.246.100.0
    netmask 255.255.252.0
    broadcast 173.246.100.255
    gateway 173.246.103.254

Reconfigure it to look like this:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
    address 173.246.100.1
    network 173.246.100.0
    netmask 255.255.252.0
    broadcast 173.246.100.255
    gateway 173.246.103.254

iface eth0:1 inet static
    address 173.246.100.2
    network 173.246.100.0
    netmask 255.255.252.0

This will assign both IPs to the first NIC. Once you've done this save the file and run:

/etc/init.d/networking restart

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.

0

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?

4
  • first of, I use ubuntu, but seeing this is not a gateway issue, it shouldnt matter. Second, if I bring the second interface down, traffic uses the first interface, but I lose the second IP, which is the reason why I have the second interface in the first place.
    – user163365
    Jun 24, 2011 at 12:27
  • 1
    You can easily configure two addresses on a single interface with an alias. All traffic over the fast interface, two IP's configured, problem solved, no? And considering "How does linux pick the default interface, and how do I select the default one?", how is this not a gateway issue?
    – wzzrd
    Jun 24, 2011 at 12:29
  • 1
    Won't work, since these are virtual interfaces, probably configured to route only the data that comes in at the specified ip. Also, this problem is about the interface, not the gateway, since the gateway is the same in both interfaces.
    – user163365
    Jun 24, 2011 at 12:32
  • 2
    Incoming requests might arrive on one interface, but outgoing stuff is already going via a random interface anyway. Try the advice, drop one of the interfaces, put the other IP on the other with an alias and see if it works. If they are, as you say, virtual, then why the difference in speed and why the attempt at separation? Something doesn't gel. Jun 24, 2011 at 12:41

You must log in to answer this question.

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