Jarno Rankinen a révisé ce gist . Aller à la révision
1 file changed, 29 insertions, 18 deletions
10-wg-reload.sh
| @@ -1,19 +1,30 @@ | |||
| 1 | - | #!/bin/bash | |
| 2 | - | ||
| 3 | - | ## | |
| 4 | - | ## Reloads Wireguard tunnel when an interface change happens | |
| 5 | - | ## Intended for use with always active full tunnels | |
| 6 | - | ## Place in /etc/NetworkManager/dispatcher.d, change permissions | |
| 7 | - | ## to 755 and enter your interface name to WG_INTERFACE | |
| 8 | - | ## (e.g. WG_INTERFACE='wg0') | |
| 9 | - | ## | |
| 10 | - | ||
| 11 | - | WG_INTERFACE='' | |
| 12 | - | ||
| 13 | - | if [[ "$1" != "$WG_INTERFACE" ]] && [[ "$2" == "up" ]]; then | |
| 14 | - | echo "running $0" | systemd-cat -t nm-dispatcher | |
| 15 | - | sleep 2 | |
| 16 | - | nmcli conn up $WG_INTERFACE | |
| 17 | - | fi | |
| 18 | - | ||
| 1 | + | #!/bin/bash | |
| 2 | + | ||
| 3 | + | ## | |
| 4 | + | ## Reloads Wireguard tunnel when a physical interface change happens | |
| 5 | + | ## Intended for use with always active full tunnels | |
| 6 | + | ## | |
| 7 | + | ## Also when using a second VPN, disables the WG tunnel when | |
| 8 | + | ## enabling the alternate and vice versa | |
| 9 | + | ## | |
| 10 | + | ||
| 11 | + | # interface names as shown by 'ip a' | |
| 12 | + | WG_INTERFACE='' | |
| 13 | + | ETH_INTERFACE='' | |
| 14 | + | WIFI_INTERFACE='' | |
| 15 | + | ALT_VPN='' | |
| 16 | + | ||
| 17 | + | if [[ "$1" == "$ETH_INTERFACE" ]] || [[ "$1" == "$WIFI_INTERFACE" ]] && [[ "$2" == "up" ]]; then | |
| 18 | + | echo "running $0: $1 $2" | systemd-cat -t nm-dispatcher | |
| 19 | + | sleep 2 | |
| 20 | + | nmcli conn up $WG_INTERFACE | |
| 21 | + | resolvectl flush-caches | |
| 22 | + | elif [[ "$1" == "$ALT_VPN" ]] && [[ "$2" == "up" ]]; then | |
| 23 | + | echo "running $0: $1 $2" | systemd-cat -t nm-dispatcher | |
| 24 | + | nmcli conn down $WG_INTERFACE | |
| 25 | + | elif [[ "$1" == "$ALT_VPN" ]] && [[ "$2" == "down" ]]; then | |
| 26 | + | echo "running $0: $1 $2" | systemd-cat -t nm-dispatcher | |
| 27 | + | nmcli conn up $WG_INTERFACE | |
| 28 | + | fi | |
| 29 | + | ||
| 19 | 30 | exit 0 | |
Jarno Rankinen a révisé ce gist . Aller à la révision
1 file changed, 0 insertions, 0 deletions
gistfile1.txt renommé en 10-wg-reload.sh
Fichier renommé sans modifications
Jarno Rankinen a révisé ce gist . Aller à la révision
1 file changed, 19 insertions
gistfile1.txt(fichier créé)
| @@ -0,0 +1,19 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | ||
| 3 | + | ## | |
| 4 | + | ## Reloads Wireguard tunnel when an interface change happens | |
| 5 | + | ## Intended for use with always active full tunnels | |
| 6 | + | ## Place in /etc/NetworkManager/dispatcher.d, change permissions | |
| 7 | + | ## to 755 and enter your interface name to WG_INTERFACE | |
| 8 | + | ## (e.g. WG_INTERFACE='wg0') | |
| 9 | + | ## | |
| 10 | + | ||
| 11 | + | WG_INTERFACE='' | |
| 12 | + | ||
| 13 | + | if [[ "$1" != "$WG_INTERFACE" ]] && [[ "$2" == "up" ]]; then | |
| 14 | + | echo "running $0" | systemd-cat -t nm-dispatcher | |
| 15 | + | sleep 2 | |
| 16 | + | nmcli conn up $WG_INTERFACE | |
| 17 | + | fi | |
| 18 | + | ||
| 19 | + | exit 0 | |