Ubuntu – How to automatically connect to VPN with Network-Manager

cisconetwork-managervpnvpnc

I do have a working VPN connection. Now I want this VPN connection to automatically activate when I'm in a certain wireless network. Is there a non-intrusive graphical way using network-manager-applet? If I remember correctly it worked for a while and doesn't anymore.

I made the wireless-connection in question available for all users for not having to input the password every time.

The CLI program used is vpnc with Hybrid-Auth enabled (cisco VPN-client compatible) from sroecker's PPA

EDIT: I can' try the answers anymore (because of eduroam) and since no answer seems to gain a majority of votes I'm just gonna leave it unanswered for now until one is upvoted then I'm gonna accept that.

Best Answer

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.