Skip to content

Instantly share code, notes, and snippets.

@shirish87
Last active October 18, 2025 07:05
Show Gist options
  • Save shirish87/0b7ec8054b9d73f1e4dfe419a928783c to your computer and use it in GitHub Desktop.
Save shirish87/0b7ec8054b9d73f1e4dfe419a928783c to your computer and use it in GitHub Desktop.
Automatically disable your secondary Wi-Fi when your primary Wi-Fi connects, and enable it when the primary disconnects.
#!/bin/bash
# /etc/NetworkManager/dispatcher.d/30-wifi-failover.sh
# test:
# sudo bash -x /etc/NetworkManager/dispatcher.d/30-wifi-failover.sh wlx... up
# --- CONFIGURE YOUR DEVICES HERE ---
PRIMARY_IF="wlx..."
SECONDARY_IF="wlp0..."
# -----------------------------------
# The script gets two arguments:
# $1 = The interface name
# $2 = The action (e.g., "up", "down")
IFACE="$1"
ACTION="$2"
# We only care about events from our primary interface
if [ "$IFACE" != "$PRIMARY_IF" ]; then
exit 0
fi
case "$ACTION" in
"up")
# The primary interface just came UP (connected).
# We must disable the secondary interface.
logger "NM Dispatcher: $PRIMARY_IF is UP. Disabling $SECONDARY_IF."
nmcli device set $PRIMARY_IF managed yes
nmcli device set $SECONDARY_IF managed no
;;
"down")
# The primary interface just went DOWN (disconnected).
# We must enable the secondary interface as a fallback.
logger "NM Dispatcher: $PRIMARY_IF is DOWN. Enabling $SECONDARY_IF."
nmcli device set $SECONDARY_IF managed yes
nmcli device set $PRIMARY_IF managed no
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment