Disable WiFi when Wired Network is avalable

Lars Jönsson, 2024-05-08

This guide describes a method for automatically disabling WiFi when an Ethernet cable is connected. It is based on a Disable WLan if Wired/Cable Network is available.

Installation

Create the file /etc/NetworkManager/dispatcher.d/99-wlan with the following content.

#!/bin/bash
wired_interfaces="en.*|eth.*"
if [[ "$1" =~ $wired_interfaces ]]; then
    case "$2" in
        up)
            nmcli radio wifi off
            ;;
        down)
            # Ignore if VLAN
            if [[ "$1" == *.* ]]; then exit; fi
            nmcli radio wifi on
            ;;
    esac
fi

Change the attributes of the file to make it executable.

chmod +x /etc/NetworkManager/dispatcher.d/99-wlan