# How to work with 2 network interfaces

## Gh0str1d3r

Hi,

I have a laptop with 2 network interfaces: one wifi and one wired. Now, when both interfaces are up and connected to some network, but only one has internet, the system is confused and I can connect to neither of the networks. My question is now how to tell the system which interface handles which request (e.g. internet through eth0, local ip addresses through wlan0), or even better how to let the interfaces decide this automatically.

----------

## eccerr0r

Not sure what you want here.  By the nature that local addresses should be on the same subnet, it should use that subnet if an IP address is presented along that subnet...  What is your routing table like?

You should have only one default route, and that's out of your LAN.  The WLAN/LANs should be simply a subnet route with no default...

I've found that GNOME's networkmanager applet (nm-applet) seems to work well with temporary interfaces automatically... but I think you meant different problem, but just in case... (nm-applet seems to work fine for me for my laptops, but neither of which tend to use both ethernet and wlan at the same time, it's either one or the other at any one time.)

----------

## Gh0str1d3r

I often have the case that my laptop is on a wired network, while there is also known wifi available. So I am connected to 2 completely different networks simultaneously. I don't want to disable one of the network cards to get internet in that case. In particular, when I can get internet through the cable, I want to use that one, otherwise use the wifi. This should happen without the need to change anything manually on every reboot.

----------

## eccerr0r

Networkmanager seems to handle that case for me, when I'm plugged into my LAN via Gbit and still within range of my 802.11g...  It will automatically use the LAN until I pull the cable, and then it will switch over to wifi.

It's not perfect all the time though, any open connections will still break, but mostly the transition is fairly automatic and transparent.

However if both networks are on different, unrelated networks (both have different gateways) then things get a bit more confusing.  It still should favor Ethernet's gateway over wifi though.  But both subnets should still be visible at least last I tried with this situation...

----------

## Gh0str1d3r

ok thanks for the tip, I will try it with NM. Hopefully, knetworkmanager has improved since I used it last time...  :Smile: 

However, just in case someone knows, I would be also interested in how one define a certain interface to be the one for internet manually (without disableing all other connected interfaces).

----------

## eccerr0r

It's the "default route" in your routing table that chooses which interface packets go out upon.

Theoretically if you have two interfaces on the same network they should still have different IP addresses.

The default route points which interface gets packets when the destination doesn't appear on the routing tables.

If you type "route" it would show something like

```
Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

xxa.xxb.xxc.xxd 0.0.0.0         255.255.255.248 U     0      0        0 eth0

10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0

192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth1

127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo

0.0.0.0         xxa.xxb.xxc.xxe 0.0.0.0         UG    0      0        0 eth0

```

Despite I have more than one network and even more than one network on one interface, the default is through eth0 through the "UG" xxa.xxb.xxc.xxe (and not through a 10.x.x.x address)... and there can only be one.  I can still access both the 10.0.0.0 and 192.168.0.0 subnets through *this* computer while accessing out of both internal lans, through xxa.xxb.xxc.xxe.

See "route" ... normally you'd "route del default; route add default gw gateway.address.of.interface" to select one manually.  There can only be one default.

BTW, this is NOT my laptop.  This is my server... the laptop with networkmanager should reroute the default automatically and you typically won't have to do anything special to automatically used wired network...that is unless the wired network gateway is down, then I'm not sure what it would do...

----------

## gerdesj

Actually it is perfectly valid to have multiple connections on the same subnet and you should get two default routes but with different metrics.  The one with the lower metric is the route that will be used.  If you enable ifplugd then this is all handled for you.  No need to muck about with network manager.

I have an eth0 and a wlan0 and a ppp0 and ppp1 - wired LAN, WLAN, and mobile connections via bluetooth.

If both LAN and WLAN are connected then I get two default routes but the LAN connection (eth0) has a lower metric and so that is used in preference to the WLAN.  If neither work then I start the bluetooth on my mobile.  If that is a little slow then I start it on my wife's mobile as well and enjoy multilink ppp!

Basically, you need to use ifplugd or similar (see net.example) to get your system to recognise when a net connection is down.

Or you could do it by hand with network manager.

Cheers

Jon

----------

