Ubuntu – VPN disconnect – do not stop internet

18.04internetvpn

By default (I guess) Ubuntu cuts my internet connection whenever I disconnect a VPN, which is nice unless you don't want it, and have to reconnect (stop and start) your connection every time. How can I configure it so that it does not block my traffic after disconnecting a particular VPN connection?

Best Answer

A workaround for this issue is to create a dispatch script for Network-Manager that will do this automagically for you.

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 $?

Make sure to make it executable as well:

chmod +x /etc/NetworkManager/dispatcher.d/80-ppp-vpn-down