Vpn Disconnect - Do Not Stop Internet

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?

1 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest