Disable WLan if Wired/Cable Network is available

You can drop this script to /etc/NetworkManager/dispatcher.d/99-wlan:

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

Don't forget afterwards:

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

This catches the legacy eth* names and the new kernel "predictable named interfaces" that start with en and then use either the bus path or the MAC address so that the name of each interface is the same on every boot. This worked with the USB-C (passthrough) and USB ethernet adapter I tried with and I'm confident it will work with built-in adapters as well.


Since v0.9.10 of network-manager, the first script has to be modified

#!/bin/bash

if [ "$1" = "eth0" ]; then
    case "$2" in
        up)
            nmcli radio wifi off
            ;;
        down)
            nmcli radio wifi on
           ;;
   esac
fi

Hope it helps!


Quite simply for the gnome GUI approach...

  1. Right click on the network system indicator in the gnome panel up by your clock. (The indicator will be one of two icons; either the up/down arrows (LAN) or the traditional WiFi Funnel. Note that the up/down icon will appear when both LAN & WiFi or only LAN are connected and the WiFi funnel appears when connected via WiFi ONLY. (LAN Disconnected)) -- [LAN trumps WiFi automatically.*]

  2. Select 'Edit Connections...'

  3. Select the 'Wireless' tab.
  4. Double click the first connection in your list and Uncheck the 'Connect automatically' box.
  5. Click the 'Apply...' button.
  6. Repeat for each connection in the list.

This will leave the Wireless network operational for on-the-fly manual connections and disconnections available by left clicking the network icon, without the NM trying to Automatically connect you all the time.

Naturally you could also disable/enable Wireless by right clicking the network icon and then left clicking on the "Enable Wireless' selection, effectively bringing down or up the Wireless interface as indicated by the presence or absence of the check mark.

  • LAN trumps WiFi automatically, there is no need to disable WiFi. Simply unplugging your Ethernet cable will seamlessly transfer the connection to WiFi and you can pick up and move about without any fuss. Likewise, with reconnecting the LAN.
  • While LAN does trump WiFi the NM (Network Manager) will find what you seek should you be on different networks simultaneously and are working both online (WiFi) and with a local host (LAN) or V/V for example.