Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've been looking at how I can setup a laptop that has multiple network interfaces, but a problem exists if all the connections are active, i.e. 3G, WiFi and LAN are all connected, I would like it to default to LAN.

I would like to set "weights" or "priority" to each connection, so that if the LAN is unplugged, it'll default to WiFi - if its in range and working, otherwise, it'll switch and use the 3G dongle;

I've been looking around and I can see that the "metric" counter for route isn't being used for recent kernels. I thought that would be able to set the preferred gateway / connections - but according to the man page:

man route:

OUTPUT

Metric The 'distance' to the target (usually counted in hops). It is not used by recent kernels, but may be needed by routing daemons.

So I'm confused, are there any scripts / apps / anything that can detect active network connections, and by way of configuration, send my default gateway network traffic through that interface if its active / alive?

share|improve this question

migrated from stackoverflow.com May 31 '11 at 19:02

This question came from our site for professional and enthusiast programmers.

    
What tool are you currently using to connect? I use WPA-supplicant, but I'm not sure about its support of 3G connections. This allows you to set up a plain-text config file with the highest priority connections at the top of the list. –  nalroff Jan 11 '11 at 16:34
    
metric is meant to be used for multipath routing IIRC, which worked on 2.2 and 2.4 with a patch by Julian Anastasov IIRC. –  ninjalj Jan 11 '11 at 21:37
    
This software of mine might be useful if you don't mind a bit of programming. code.google.com/p/badvpn/wiki/NCD . It's special kind of programming language especially suited to implementing dynamic network and other configurations. This example shows how to implement priorities, code.google.com/p/badvpn/wiki/… . Unfortunately, it doesn't support 3G yet. –  Ambroz Bizjak Jun 5 '12 at 20:01
add comment

1 Answer

Linux usually decides routing based on the interface metric. Look at 'route -n' and see what it says. If you have one default gateway (0.0.0.0) with a higher metric, that one will be preferred over all the others.

I'm honestly now sure how linux chooses to route if all the gateways are the same--but the point is that you need to give one default gateway a higher metric.

It's been a while since I've touched Network Manager, but I believe there are settings in there for what metric to give the gateway.

Worst case you could use the 'ip route' command to remove and re-add a gateway with a different metric. For example:


 ip route del 0.0.0.0/0 via 1.2.3.4 dev eth0
 ip route add 0.0.0.0/0 via 1.2.3.4 dev eth0 metric 1
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.