Two network cards, which provides internet?

I have mainly found questions on how to set up one network interface to have a certain IP address and the other on a different network, but I am interesting in what happens if I have two network cards (eth/wan or two wireless) set up to connect to the same router and both to the Internet.

Which of the two does my computer use to connect to websites? Do I experience drop in connection if either of the two disconnects?


Solution 1:

route -n

will show the active connection.

By default the one with the lowest priority number takes precedence. You can set up your network to have both wired active at the same time. Same can be done with wireless (but will require a unique router connection for each).

For wireless you can set a priority for all wireless but not in relation with wired. It is called connection.autoconnect-priority. In case you have a desktop: networkmanager has it also in its options under "general".

nmcli connection modify {networkwifiname} connection.autoconnect-priority 10

where 10 is the priority (lower is more). nmcli -f NAME,UUID,AUTOCONNECT,AUTOCONNECT-PRIORITY c will list the current priority.

Wired will always override wireless but you can use ifmetric (apt install ifmetric) if you want to set wireless before a wired network.

ifmetric {networkname} 10

will set it to 10.

Solution 2:

If you have multiple WAN connections and both are set up correctly, the system will set up default routes for you. Those are a "catch-all" rule for everything that is sent.

If an interface does not have a WAN connection (or if the network should not be the default for other reasons), that default route won't be created (or rather, the router won't advertise that route) and only a "targeted route" is present.

In my case, the route list looks like this:

$ ip route
default via 10.2.0.1 dev enp9s0 proto dhcp metric 100 
default via 192.168.178.1 dev wlp6s0 proto dhcp metric 600 
10.2.0.0/24 dev enp9s0 proto kernel scope link src 10.2.0.2 metric 100 
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown 
192.168.178.0/24 dev wlp6s0 proto kernel scope link src 192.168.178.210 metric 600

One of those connections (10.2.0.1) is a LAN connection, the other is wireless (192.168.178.1). If both are present, the number at the end decides which connection should be preferred, the lower number having higher importance.

As far as I know, a drop of one connection won't be unnoticable (since it usually takes a few seconds to recognize that a connection was actually dropped), but it should fail over to the other without issues (unless you are within a transfer, which not all clients/servers can handle).