Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If a Ubuntu 11.04 machine is connected to WiFi and 3G simultaneously, how do I set the priority to let the applications (browser etc.) to use WiFi first? If that's not available, it should use the 3G.

Basically, I would like to set the order in which the network connections are used.

Edit: I am looking for an easier approach which would be useful for those who are just comfortable and not experts in Ubuntu/Linux.

share|improve this question
up vote 6 down vote accepted
  1. Prioritising interfaces for general traffic is done by manipulating the routing metrics. Each route has associated parameters such as hop-counts and bandwidths. See netstat -nr and the "metric" option in the man-page for route command.

  2. Prioritising application access to network resources is often addressed by "traffic shaping" - I'd use a web search-engine to see if Ubuntu or the router can do that.

share|improve this answer
In the man page for route "Metric The 'distance' to the target (usually counted in hops). It is not used by recent kernels, but may be needed by routing daemons.". I am not sure if on a regular Ubuntu Desktop the Metric parameter will have any effect. – Praveen Sripati Sep 14 '11 at 10:18
Can you please give me the specific route command to do this? – Praveen Sripati Sep 14 '11 at 11:47
@PraveenSripati - I don't believe you gave a 100 of your hard earned rep for such an answer - technically correct, but does not help you or me. :-( I am looking for a specific command as well. – Lord Loh. Nov 15 '13 at 17:58

Setting the metrics is how you change priorities. The higher metric is more "expensive" to use, so the OS will use the interfaces with the lowest metric if it needs to route traffic. In case the lower metric interface is shutdown it will use the higher metric interface since it is the only interface which can be used to route traffic towards that particular network/destination.

The metrics are specified in the file /etc/network/interfaces, link points to the documentation.

Use any text editor to edit the file, identify the networks, and just change the metric parameter and save. Reboot is the simplest way to reset all the values without getting into the geeky details of restarting the network services.

share|improve this answer
Harry - Thanks for the response - The network I am interested in eth1 is shown in the "ifconfig", but not in "/etc/network/interfaces". What are shown in "ifconfig" and what in "/etc/network/interfaces"? – Praveen Sripati Sep 9 '11 at 14:50
Adding eth0 to "/etc/network/interfaces" is more risky. You could try ifconfig as root to change the metric for the interface (check that it stays there after the boot). – harrymc Sep 9 '11 at 15:11
When I ran 'sudo ifconfig eth1 metric 4' I got the following error 'SIOCSIFMETRIC: Operation not supported'. says that 'Additionally, not all systems make use of the metric argument. ..... When configuring a Linux system, you add an explicit route command for each interface." Looks like there is no straight forward approach in Ubuntu like from a UI for a novice user. – Praveen Sripati Sep 9 '11 at 17:06
It looks like Linux decides itself on the fastest adapter after a quick speed test on all adapters. Metric is no longer supported on many distributions. You can still try and dictate things via "/etc/network/interfaces", but I don't know how successful you will be. See also this question. – harrymc Sep 9 '11 at 19:06
The simplest solution, which everyone does, is just to turn off the interface you don't want to use, or to limit it to "Use this connection only for resources on its network" (if you also have your printer or whatever on that same router). – harrymc Sep 10 '11 at 12:14

I haven't really tried it out, but NCD (Network Configuration Daemon - 1) can be used for this purpose. The site claims to make the network configuration easy. The syntax seems to be simple.

#Wait for some network connection. Prefer eth1 by putting it in front of eth0.
list("NET-eth1", "NET-eth0") pnames;

(1) -

share|improve this answer
You're right, my NCD software does this nicely; the example there works as-is. I should note however that the pnames list is in fact just an argument to the multidepend() statement on the next line - this is the one which implements the priorities. The mechanism behind this is that when eth1 comes up when eth0 is already up, it executed multiprovide("NET-eth1");, because NET-eth1 is in front of NET-eth0, multidepend() will go down and come back up immediately, but exposing variables from the eth1 process instead of eth0. – Ambroz Bizjak Sep 11 '11 at 13:47

You must log in to answer this question.

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