Tag Archives: networkmanager

Automatically enable and disable WiFi based on Ethernet connection with NetworkManager

I use a laptop as my daily driver and am on WiFi most of the time. However, I also have a dock which has Ethernet. Thanks to NetworkManager dispatcher scripts, we can automatically disable WiFi when Ethernet is connected and then enable it again once Ethernet is disconnected.

NetworkManager will execute scripts in the /etc/NetworkManager/dispatcher.d directory in alphabetical order in response to network events. Each script should be (a) a regular file, (b) owned by root, (c) not writable by group or other, (d) not set-uid, (e) and executable by the owner. Each script receives two arguments, the first being the interface name of the device just activated, and second an action.

https://linux.die.net/man/8/networkmanager

Let’s create the script (this is not mine, it comes from the nmcli-examples man page).

Continue reading