I have two different network interfaces, connected to 2 networks. One is an eth0 and the other one a wlan0. How can I tell a software to use only a specific interface?

Basically I want Firefox to use eth0 because it is the university lan network and I have to go to intranet sites, the other one is a wifi network open to the internet and I want to bind it to Chrome.

I'm working and I need to use intranet. So eth0 is my choice but eth0 is an intranet without internet access (obviously). Since I want internet access I'm connected to wlan0 (university wifi for students).

The problem is if I have both connected sometimes the browser looks for www.stackoverflow.com using eth0. So I wanted to assign a browser to use only a specific interface.

  • Isn't routing a better solution for your problems?. I mean, that connections to ubuntu.stackexchange.com should use the same interface from any program. Sep 29, 2010 at 8:58

2 Answers 2


You cannot bind client software to specific network interfaces, but you can tell the kernel that you only want to use one network interface for some IP addresses and the other one for everything else. This is called "routing", and can be configured using the commands /sbin/route and /sbin/ip.

If I read your question correctly, you want to connect to intranet IP addresses using interface eth0 and to the Internet using interface wlan0.

If you run the command ip route list, you should see an output like the following (numbers will be different, and also you can have more lines in it):

$ ip route list dev eth0  proto kernel  scope link  src  metric 1 dev wlan0  proto kernel  scope link  src  metric 2 
default via dev eth0  proto static 

The first two lines tell you about the networks connected to interfaces eth0 and wlan0: network traffic directed to computers on those networks will be directly sent to them through the corresponding interface.

The last line tells you what the "default route" is: if your computer wants to talk to a computer on a network it is not attached to (e.g., the stackoverflow.com server), it will route traffic via eth0, realying through host (called the "default gateway").

So, to route Internet traffic thorugh wlan0 you should ensure that the last line in the ip route list output reads something like:

default via A.B.C.D dev wlan0 proto static

where A.B.C.D is the IP address of the gateway on the wireless LAN. If the output does not contain "dev wlan0", you can change it with the command:

sudo ip route change to default dev wlan0 via A.B.C.D

You can find out the correct A.B.C.D for wlan0 in two ways:

  1. Look into directory /var/lib/dhcp3/: you should find some dhclient-...-wlan0.lease files. Open the most recent one and search for a line with the string option router in it: the rest of the line tells you the IP address A.B.C.D.

  2. Ask your local network administrators. (Probably the best thing to do, anyway.)

With this configuration, you should be able to:

  • browse the Internet through wlan0
  • browse your Intranet through eth0, provided it is on a single network.

If your intranet spans multiple networks, then you will need to add routes for them - and this is definitely something that requires you to interact with the local network admins. :-)

  • 1
    Just out of curiosity: what if I want to bound dns (to include subdomains) rather than IP addresses?
    – dierre
    Sep 29, 2010 at 16:15
  • 1
    @dierre In short: you can't, routing is based on IP addresses. The long story begins by telling that routing is a network layer 3 thing, so it won't even know about DNS names, whose resolution happens further up the networking protocol stack... Sep 29, 2010 at 18:40
  • yeah yeah, I didn't mean with routing. I mean in general. Can it be done? Binding DNS to network interfaces?
    – dierre
    Sep 29, 2010 at 19:28
  • @dierre What exactly do you want to do? Making a DNS server answer only on a specific network interface? Or having a DNS client (i.e., DNS resolution) use only a selected interface? Sep 29, 2010 at 20:18
  • 1
    @Riccardo Murri: ubuntu.stackexchange.com/questions/4988/… et voilà
    – dierre
    Sep 30, 2010 at 19:48

"ip netns" creates network namespaces. You can then create virtual interfaces (ip link add... veth) and associate them to the namespaces.

The namespaces can be configured to use different routes for example (thus using different interfaces)

Then you can run commands in that namespace, that will use the created namespace.. "ip netns exec NAME cmd..."

Source: http://manpages.ubuntu.com/manpages/saucy/en/man8/ip-netns.8.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.