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.
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
:[I haven't tested this -- please feel free to test and edit according to results]
See: https://wiki.archlinux.org/title/NetworkManager#Use_dispatcher_to_connect_to_a_VPN_after_a_network_connection_is_established has more info.
You can find VPN auto-connect option in the
nm-connection-editor
GUI in the individual saved Wi-Fi settings. In Ubuntu 14.04 you can find it under:System settings -> Network -> Wi-Fi or Lan -> Settings (General tab) -> Auto connect to VPN...
(Since Gnome 42, this path leads to a new simplified menu, but the complete one can still be accessed through
nm-connection-editor
directly)After saving, a
secondaries=
line is added in your configuration file in the[connection]
section. It will contain a list of secondary connection UUIDs to be activated. The configuration file is usually/etc/NetworkManager/system-connections/
.This information can be useful if you need to activate more than one secondary connection. You can add multiple connection UUIDs in the configuration file separated by
;
, even though the GUI (at the moment: 2022) does not allow to select more than one entry.I was able to get this working on Ubuntu 20.04 by using
nm-connection-editor
. For whatever reason, the option doesn't appear anymore in neither the Wifi/Ethernet nor the VPN config UIs.Open a terminal
Type
nm-connection-editor
Select the network connection you want to auto-connect
Click the gear icon to open settings for that connection
Go to the General tab
Enable the
Automatically connect to VPN
option and select the VPN in the dropdown menu to the rightClick Save
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:
Hope that helped.
I can confirm this following solution working for me. I am running Ubuntu 14.04 LTS.
I went to the shutdown icon and then system settings.
When the settings screen opens, I went to 'Network' and the WiFi network with which I was connected. There is a small arrow one one side of the name of the network.
Click that icon and you should see an option called "settings" or "options" (or something similar) here:
When the next window opens, simply go to the 'General' tab and you should see an option that gives you an option to Automatically connect to a VPN. Choose the VPN You'd like to connect when connected to this WiFi, and boom! Everytime you connect to this network, Ubuntu will also connect you to that VPN. :)
For me its working. I hope it works for everyone else too. Doesn't require any sort of text editor or code editor or anything..
If you prefer terminals, you can use
nmcli
, I did it using the following commands:First, find and open the VPN connection you want to update
This will open the nmcli prompt, from here you can query the values and set them, like this:
And you should be done!
You don't need any dispatcher scripts any more ! In 14.04 (Trusty Tahr) you just have to take the following steps after setting the autoconnect option in the NetworkManager GUI.
Store the vpn-secrets plainly in the config file for the VPN-connection under
/etc/NetworkManager/system-connections/YourVPNConnectionName
.You can achieve this by setting
IPSec secret-flags=0
andXauth password-flags=0
in the config file. Then go to the NetworkManager GUI and save again you VPN-connection settings. Now a section called [vpn-secrets] should be present in the config file. Doublecheck it and autoconnection should be working now !Even though the man page lists
nmcli con status
as a valid command, The above solution provided byHugo Heden
returns an error"Error: Object 'status' is unknown, try 'nmcli help'"
I'm using nmcli 1.2.2 (
nmcli -v
) and I've tested and modified the following for/etc/NetworkManager/dispatcher.d/vpn-up
and it worked like a charm.Note: You can use
nmcli con show
to see all connection names as they aren't always the same as what's listed in the Network Connections GUIYou can add the uuid of the VPN profile by using the "secondaries" field in your primary connection
For example,
/etc/NetworkManager/system-connections/Wired
Reference https://developer.gnome.org/NetworkManager/stable/nm-settings.html
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:
Now if you connect to a network (either wifi or ethernet), it will also try to setup VPN connection.