1

If I have two network devices, how do I know which is being used for any requested connection out.

With this :

ip r default via 10.0.0.1 dev wlp3s0 proto static default via 10.0.0.1 dev wlx00e04c221395 proto dhcp src 10.0.0.143 metric 600 10.0.0.0/24 dev wlp3s0 proto kernel scope link src 10.0.0.120 10.0.0.0/24 dev wlx00e04c221395 proto kernel scope link src 10.0.0.143 10.0.0.1 dev wlx00e04c221395 proto dhcp scope link src 10.0.0.143 metric 600 

I have two default routes. Will system always use the first as listed by the ip r command?

2 Answers 2

2

Check your route table with below command, here Metric column normally decide what is the routing priorities,

$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.42.0.2 0.0.0.0 UG 50 0 0 eth1 0.0.0.0 10.42.0.1 0.0.0.0 UG 100 0 0 eth0 

This priority is depending on sequence of interface come up after reboot/start, you can also influence the priority with below command

sudo ifmetric <interface> <priority> 
4
  • Even better, use ip route get a.b.c.d to find out which network device the kernel will use to reach IP address a.b.c.d. This also works when the routing table isn't that obvious as in your example... Commented May 31, 2019 at 17:19
  • @dirkt Interesting. This shows consistently ( 5 cycles) a different device used to route to my DNS than to my gateway. How's that? Commented May 31, 2019 at 17:24
  • @StephenBoston: Two identical routes with same metric for the target address? That's never a good idea... the answer is usually "fix your network setup so this doesn't happen". Commented May 31, 2019 at 17:27
  • @dirkt Do you mean that ip r should show only one default for the routing table? Or that there should be only one default for the device? Commented May 31, 2019 at 22:34
1

I think the discussion in the comments to the other answer deserve their own answer:

First, while you can list the routing table with ip route or route -n and work out yourself what's likely going to happen, it's easier to just ask the kernel with ip route get a.b.c.d to go through the routing tables (yes, there's more tables in a modern Linux system, and route -n only shows the main table) and tell you the outcome.

Second, a rule of thumb for designing a network is "each host only gets a single network interface into each subnet it is connected to". Here VMs, network namespaces etc. count as additional "hosts", even if they run on the same hardware.

A corollary is "no, you don't assign multiple IPv4 addresses to the same network interface" (unless you know what you are doing, but then you do that at your own peril).

The reason is that nothing is won by making a subnet accessible through different network interfaces: It will go into the same subnet one way or the other.

If you violate these rules, as you did above, where you apparently have two WLANs connected to the same subnet:

10.0.0.0/24 dev wlp3s0 proto kernel scope link src 10.0.0.120 10.0.0.0/24 dev wlx00e04c221395 proto kernel scope link src 10.0.0.143 

then what happens is not defined. As you can see, the linux kernel happily picks one of the network interfaces at random for destinations 10.0.0.*.

So either these are really connecting to two different WLANs. In that case, change the IP range of one of the WLANs, e.g. to 10.0.1.0/24. Or, they are the same WLAN, and in that case having two WLAN adapters makes no sense.

It's similar with the default rule. You should only have a single default rule; having multiple rules means the behaviour is undefined, and a rule gets picked at random. This means that packets in one connection are randomly sent with different parameters (e.g. source addresses), and the host on the other hand will only recognize one set of parmameters (the one the connection was opened with), will drop the other packets, and will consider the missing packets as lost packets. That's because the standard internet protocols are "single homed". There are multi-homed protocols (like SCTP or multi-home TCP extensions), but they are currently not used widely enough to be useful.

So no, you can't use two ISPs to connect to the internet and make "the internet faster" (unless you have some hard way of deciding which connection to use, e.g. by destination address). That's a FAQ that gets asked every week or so.

I hope that answers all (or at least most of) the questions you didn't ask in your original question.

2
  • Perfect. Thank you. I'm one of those mad tinkers whose path of learning will frequently blow up the lab. But making the internet faster wasn't the goal. I feel that you're taking potshots from your lofty presumptions. You were doing great up til then. Commented Jun 1, 2019 at 13:39
  • 1
    Sorry, no potshotting intended - I've just seen too many of the same type of questions on this site, and it gets a bit tiring to always answer the same ones. Combine that with XY questions (which also happen frequently), and the inability to directly talk to the person who is asking the question, and then it just speeds up thinks to make assumptions (or presumptions, or take potshots, if you want to put it that way). Even if they turn out to be wrong, as in your case. And there's nothing wrong with blowing up the lab :-) Commented Jun 1, 2019 at 14:27

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.