Pick the default network interface
Solution 1
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.
Solution 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.
Related videos on Youtube
Comments
-
user163365 over 1 year
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
-
Govindarajulu almost 13 yearsInteresting, as the ifconfig manpage states this at the section about "metric": This parameter sets the interface metric. It is not available under GNU/Linux.
-
Caleb almost 13 yearsGlad 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.
-
user163365 almost 13 years@Caleb: I was still on the timeout, I've posted my anwser
-
-
user163365 almost 13 yearsfirst 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.
-
Govindarajulu almost 13 yearsYou 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?
-
user163365 almost 13 yearsWon'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.
-
EightBitTony almost 13 yearsIncoming 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.
-
CMCDragonkai over 8 yearsDoes this change the default gateway immediately or after rebooting?