- Gnome 40 and above (Tested on Gnome 46)
- An already configured wireguard VPN connection (via the NetworkManager)
- Using root, create a script file in /etc/NetworkManager/dispatcher.d/wireguard.shand make it executable ug+x
- Add the following content:
#!/usr/bin/env bash interface=$1 event=$2 active_wg=$(nmcli connection show --active | grep wireguard | cut -d " " -f1) wireguard_connection_name="PUT_HERE_YOUR_WIREGUARD_CONNECTION_ID" if [[ "$interface" = "wlo1" ]] && [[ "$event" = "down" ]] && [[ -n "$active_wg" ]]; then echo "WIREGUARD: wifi is down. turning off wireguard" | systemd-cat -p info -t wireguard nmcli connection down "$wireguard_connection_name"; fi if [[ "$interface" = "wlo1" ]] && [[ "$event" = "up" ]] && [[ -z "$active_wg" ]]; then echo "WIREGUARD: wifi is up. turning on wireguard" | systemd-cat -p info -t wireguard nmcli connection up "$wireguard_connection_name"; fi 
- Find your wireguard connection id using nmcli connection show | grep wireguardand notice the 1st column in the output
- Replace the "PUT_HERE_YOUR_WIREGUARD_CONNECTION_ID" in the above wireguard.shfile
- The wireguard connection should now follow the status of your wifi
- Debug using journalctl, e.g.,journalctl --utc --since "15 minutes ago" -t wireguard