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.
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 interfacewlan0
.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):The first two lines tell you about the networks connected to interfaces
eth0
andwlan0
: 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 host10.60.44.1
(called the "default gateway").So, to route Internet traffic thorugh
wlan0
you should ensure that the last line in theip route list
output reads something like: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:You can find out the correct
A.B.C.D
forwlan0
in two ways:Look into directory
/var/lib/dhcp3/
: you should find somedhclient-...-wlan0.lease
files. Open the most recent one and search for a line with the stringoption router
in it: the rest of the line tells you the IP addressA.B.C.D
.Ask your local network administrators. (Probably the best thing to do, anyway.)
With this configuration, you should be able to:
wlan0
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. :-)
"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