NetworkManager and (not) dealing with conflicting network connections

June 26, 2020

I recently tweeted a wish for NetworkManager:

I wish there was some straightforward way to tell NetworkManager to not automatically connect to any wifi networks if my laptop has a wired network connection, while still auto-connecting if there is no wired Ethernet.

In NetworkManager you can set a priority for network connections, but as far as I can tell you can't tell it that two connections conflict with each other and should never be brought up at the same time. You can write scripts that run when connections change and that take down connections (on Twitter @zigford pointed me to a script for this here), but I don't consider this straightforward. So let me give you the story of how I have wound up wanting this.

I have a work laptop, which I've brought home periodically for short periods of light use in the past (for example over our Christmas vacations). At that point I set it up for wireless networking and to automatically connect to my home wireless for convenience. Then, thanks to current world and local events, I took my work laptop home for extended use over a longer period, and soon discovered that my home wireless network has surprisingly high and variable latency. Fortunately I'd also taken the laptop's USB Ethernet adapter and I have a little home switch, so I could change over to having my laptop use a wired connection (although not without fun discoveries).

As it happens, I don't have two home subnets, one wired and one wireless; I have one that everything is on (and the AP just extends it out from wired to wireless). When I initially set up my laptop at home on the wireless, I gave it a fixed IP address and name so that I could easily SSH to it (and because I give everything here a fixed IP address). When I 'switched' my laptop to using a wired connection, I gave that wired Ethernet address the same fixed IP address, because I had no desire to have to SSH to 'laptop-wired' versus 'laptop-wifi' (I just want to SSH to 'laptop'). Unfortunately this means that if both the wired and the wireless connections are active at once, both get the same IP and then fun things happen. Especially, some of my traffic to my laptop goes over the wireless, with increased and variable latencies, which is what I set up a wired connection to avoid.

(I'm honestly surprised that my DHCP server didn't object to handing out the same IP at once to two different things, but then I did tell it that both the wired and the wireless Ethernet addresses could have the same IP. I'm also surprised at how long it took me to notice this; I only did because I was running 'ifconfig -a' for another reason and noticed that my wifi adapter had an IP assigned.)

My current solution is to tell NetworkManager to not automatically connect to my home wireless network. This is less convenient if I want to use my work laptop from somewhere else, but in practice I almost never do (my work laptop is mostly used for video conferencing, since it has a camera and a microphone; actual work happens from my home desktop).


Comments on this page:

By Gabriel A Devenyi at 2020-06-28 14:55:55:

TLP offers the option of disabling the wifi adaptor when ethernet is plugged in, that might be an option.

By mario at 2020-06-30 12:27:07:

Look for "Example 15. nmcli usage in a NetworkManager dispatcher script to make Ethernet and Wi-Fi mutually exclusive" in the official documentation.

By cks at 2020-06-30 16:09:04:

One slightly tricky bit here is that I don't want to always disable wifi when the Ethernet is plugged in, because there are times when I want to use both (when the laptop isn't in this particular network setup). Looking at the documentation for dispatch scripts, I think this means that I'd need to hook the dhcp4-change action at least (maybe dhcp6-change as well, somehow). And ideally I don't want to kill the wifi, I just want to disconnect from this particular wireless SSID and not auto-reconnect.

All of this sounds like it's getting complicated, when it would be simple to have a little option in the GUI that is 'this conflicts with <X>' and then base things on which is brought up or down on the priority. But of course I don't have the latter.

Written on 26 June 2020.
« What Prometheus Blackbox's TLS certificate expiry metrics are checking
Understanding why Django's goals are not our goals for our web application »

Page tools: View Source, View Normal, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Fri Jun 26 22:42:14 2020
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.