I’m working with a client that has a PPTP VPN connection to get into their network. After disconnecting from the VPN, I would loose my connectivity to everything.
The routing table looked good, i.e. no default gateway or similar pointing to an incorrect gateway. Did some googling but couldn’t find any solution for it.
A workaround would be to disconnect and then connect to my LAN again. So after some more research I found out that you can create scripts in /etc/NetworkManager/dispatcher.d
. These scripts will be feeded with two arguments: interface
and state
.
Create /etc/NetworkManager/dispatcher.d/80-ppp-vpn-down
with the following contents:
#!/usr/bin/env bash ## # The environment contains more information about the interface and the connection: # DEVICE_IFACE - The interface name of the control interface of the device main() { local interface="$1" local event="$2" if [[ "${interface}" =~ "ppp"* && "${event}" == "vpn-down" ]]; then local connection connection="$(nmcli -t -f NAME,DEVICE connection show --active | awk -F: '/'"${DEVICE_IFACE}"'/ {print $1}')" || return 1 nmcli connection down id "${connection}" nmcli connection up id "${connection}" fi } main "$@" exit $?
Don’t forget to make it executable:
chmod +x /etc/NetworkManager/dispatcher.d/80-ppp-vpn-down
Now when disconnecting from a PPTP connection, your connection used on the control interface will be toggled and you’ll have network connectivity again.