How to automatically connect to VPN with Network-Manager

The solution suggested by con-f-use should work but doesn't, due to a long-standing bug:

https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/280571

There are workarounds though. For recent NetworkManager versions, there is a commandline utitility, nmcli, that can be edited and saved as something like /etc/NetworkManager/dispatcher.d/vpn-up:

#! /bin/bash

REQUIRED_CONNECTION_NAME="<name-of-connection>"
VPN_CONNECTION_NAME="<name-of-vpn-connection>"


activ_con=$(nmcli con status | grep "${REQUIRED_CONNECTION_NAME}")
activ_vpn=$(nmcli con status | grep "${VPN_CONNECTION_NAME}")
if [ "${activ_con}" -a ! "${activ_vpn}" ];
then
    nmcli con up id "${VPN_CONNECTION_NAME}"
fi

[I haven't tested this -- please feel free to test and edit according to results]

See: https://wiki.archlinux.org/index.php/NetworkManager#Use_dispatcher_to_connect_to_a_vpn_after_a_network-connection_is_established has more info.


In Ubuntu Trusty 14.04 VPN auto connect store on GUI on individual saved wi-fi settings. System settings - Network - check interested Wi-Fi or Lan - Settings (General tab) - select "Auto connect to VPN... "


If I remember correctly it worked for a while and doesn't anymore.

  • This might be obvious, but sometimes I don't think of it. Did you try reinstallation like:

    sudo apt-get purge network-manager-vpn sudo apt-get install network-manager-vpnc Then: enter image description here

Now I want this VPN connection to automatically activate when I'm in a certain wireless network.

  • There's a way to suppress the "couldn't connect"-type of messages when your users are in the wrong network, but can't remember how it went. I see no other way to automatically connect in a graphical way. Maybe you'll have to write a script doing the connecting when in said wlan-network.

Hope that helped.