Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
how are you coming along with this? –  rlemon Feb 24 '12 at 22:52
    
I didn't need it for quite a long time now. Maybe come april on new university. –  turbo Mar 6 '12 at 19:01
    
can you accept an answer or close the issue then? –  rlemon Mar 6 '12 at 19:19
    
Possibel duplicate? askubuntu.com/questions/86365 –  fossfreedom May 29 '12 at 9:48
    
@fossfreedom not a duplicate exactly because my question is about vpnc rather than openconnect. –  turbo May 29 '12 at 14:58
add comment

3 Answers

up vote 7 down vote accepted

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.

share|improve this answer
    
note that in 13.04 i had to put that script in /etc/network/if-up.d and fix /etc/NetworkManager/system-connections/connection-name according to askubuntu.com/questions/198136/… to avoid "No valid VPN secrets" error –  OlegYch May 20 '13 at 15:20
    
The Arch wiki hack does work in fact! I tried the script on the arch wiki on july 11th 2013, and modifying it from 'nmcli ...' to 'su [user] -c "nmcli..."' does not work! follow instructions as in the wiki and don't forget the chmod +x ;) cheers! –  user174385 Jul 11 '13 at 15:25
    
The bug mentioned by Hugo Eden (bugs.launchpad.net/ubuntu/+source/network-manager/+bug/280571) has been fixed upstream over 5 months ago. However, I'm still experiencing it in Precise... What gives? –  iGadget Dec 29 '13 at 14:15
add comment

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.

share|improve this answer
    
I still haven't come around to actually testing this. I'll mark it answered when I will. Promise. –  turbo Jun 16 '11 at 13:40
    
in my experience this doesn't actually work. I believe this to be a bug in NetworkManager –  Conor Rynne Jul 10 '11 at 11:42
2  
Yep this is broken, even in Precise. It doesn't connect automatically O_o –  eggonlegs Sep 12 '12 at 23:44
    
Yup -- broken. Does not work (Ubunutu 12.04). –  user48956 Apr 14 at 16:38
add comment

Use following Python script Gist #1547663.

First parameter to the script is VPN connection name in NetworkManager and the second is comma separated names of networks that should be ignored (e.g. using VPN connection at home is useless).

Example to install and let it run at boot time:

git clone git://gist.github.com/1547663.git /home/user/autovpn/
echo "python /home/user/autovpn/autovpn.py 'myvpn' 'Auto homenetwork,Auto worknetwork' > /var/log/autovpn.log&" > /etc/rc.local
/etc/rc.local

Now if you connect to a network (either wifi or ethernet), it will also try to setup VPN connection.

share|improve this answer
1  
I think this approach is less elegant, due to a background process being active for this all the time, while it could be event-driven like in the answer of @hugoheden. –  gertvdijk Dec 4 '12 at 15:37
    
It does more than his answer: it also handles VPN reconnect and cases where user manually disables vpn connection (meaning it shouldn't try to reconnect VPN in that case) –  iElectric Dec 5 '12 at 11:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.