Let ethernet take precedence over wireless when ethernet cable is plugged in
After having done a fair amount of Googling and reading I've come to a point where I believe what I should be doing is something along the lines of
nmcli connection modify [id-of-ethernet-interface] ipv4.route-metric 200 nmcli connection modify [id-of-ethernet-interface] ipv6.route-metric 200
where 200 is a lower value than the wireless metric, to have the ethernet take precedence over the wireless.
What perplexes me is the reports I get from
route -n after I have executed the above commands and rebooted (for good measure), and the fact that this doesn't seem to amount to reaching my goal
$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 123.456.89.1 0.0.0.0 UG 600 0 0 wlp1s0 0.0.0.0 123.456.89.1 0.0.0.0 UG 20200 0 0 enp0s31f6 123.456.89.0 0.0.0.0 255.255.255.192 U 200 0 0 enp0s31f6 123.456.89.0 0.0.0.0 255.255.255.192 U 600 0 0 wlp1s0 654.321.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6
The numbers add up with regards to my command execution, but for the lines that say
0.0.0.0 123.456.89.1 0.0.0.0 UG 20200 0 0 enp0s31f6 654.321.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6
The first line has 20 prefixed before the 200 value I set. This keeps being consistently applied based on what I run; If I change the value for the metric through
nmcli to say 500,
route -n will report 20500. Why does this happen? It sure doesn't look right, since I stated I wanted either 200 or 500, not 20200 and 20500.
The second line has a metric value that I have no idea where it comes from, and I can't seem to affect it at all. If anyone can shed light on this, I'm grateful.
It doesn't look like these commands end up in anything tangible, other than affecting the metrics; I cannot tell that that ethernet is taking precedence, so I assume it is not.
What I have found curious, and seem to be working to some extent, is the use of
$ sudo ifmetric enp0s31f6 200. This does two to three things;
- It affects the metric of the interface (
route -nreports all lines with the Iface
enp0s31f6to have the value 200)
- It affects the UI in Ubuntu (In the upper right corner I will see a visual switch between ethernet and wireless icons switching, depending on the metric values I provide in the
- It sometimes throws a
NETLINK: Error: File existserror at me. Subsequent executions of the same command may or may not result in this error
Some system info
- EliteBook 850 G5
- Ubuntu 18.04
- Ubuntu install made through letting the installer use the entire disc, enabled encryption, enabled 3rd party downloads for drivers, etc.
$ nmcli c show NAME UUID TYPE DEVICE Wired connection 2 [n/a] ethernet enp0s31f6 WiFi1 [n/a] wifi wlp1s0 $ route -n Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 [n/a] 0.0.0.0 UG 600 0 0 wlp1s0 0.0.0.0 [n/a] 0.0.0.0 UG 20200 0 0 enp0s31f6 [n/a] 0.0.0.0 255.255.255.192 U 200 0 0 enp0s31f6 [n/a] 0.0.0.0 255.255.255.192 U 600 0 0 wlp1s0 [n/a] 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s31f6