Skip to content

Instantly share code, notes, and snippets.

@mrlpm
Last active August 17, 2025 06:05
Show Gist options
  • Save mrlpm/c71830d0b065d330d88a03247ece550d to your computer and use it in GitHub Desktop.
Save mrlpm/c71830d0b065d330d88a03247ece550d to your computer and use it in GitHub Desktop.
Ethernet and Wi-Fi mutually exclusive

Ref.: https://man.archlinux.org/man/nmcli-examples.7.en

  1. Create an script in /etc/NetworkManager/dispatcher.d/
cat << EOF |sudo tee /etc/NetworkManager/dispatcher.d/wifi-ether.sh
#!/bin/bash
export LC_ALL=C
enable_disable_wifi ()
{
    result=$(nmcli dev | grep "ethernet" | grep -w "connected")
    if [ -n "$result" ]; then
        nmcli radio wifi off
    else
        nmcli radio wifi on
    fi
}
if [ "$2" = "up" ]; then
    enable_disable_wifi
fi
if [ "$2" = "down" ]; then
    enable_disable_wifi
fi
EOF
  1. Set execution perms
chmod +x /etc/NetworkManager/dispatcher.d/wifi-ether.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment