2

I have a working VPN connection. Works like a dream.

What isn't working though, is the 'Connect Automatically' option in the Network Connections Manager Panel. It never connects automatically, not at boot, and not after disconnect. I'm not quite sure what that option is for. And I'll get disconnected from the VPN with no warning whatsoever.

Is there a way to make sure my computer only connects to the internet through a VPN? So that if the VPN connection isn't established, my computer can't reach the internet. And is there a way to get ubuntu to attempt to reconnect to the VPN automatically if for some reason the connection drops?

3 Answers 3

5

Unfortunately "Connect Automatically" allows the VPN to connect when you try to visit a service that's not otherwise reachable, which means it won't work for maintaining VPN connections used only (or even primarily) for privacy purposes.

The only way I've found to keep VPN up is to have a crontab entry that runs

nmcli con on id YourVPNName

This assumes you've got your VPN configured via NetworkManager, which you probably do.

2
  • 2
    This is pretty awesome and may just solve my problem. Though with my version of nmcli I get Error: 'con' command 'on' is not valid. So I read the man and found up instead of on. The command that worked for me is: nmcli con up id YourVPNName My nmcli version is 0.9.4.0.
    – greg
    Commented Jul 25, 2012 at 14:41
  • Will this connect to the VPN system-wide or only for the user who have this cron configured? Commented Mar 18, 2016 at 15:00
1

As long as the automatic reconnect is concerned, you can try this - VPNautoconnect. It seems to be working pretty well (and reconnects immediately after the VPN is dropped for some reason) and has a GUI (no need to use the command line). It works with connections from the Network Manager.

1
0

I have my 12.04 connecting automatically about 1 minutes after I log in. I suspect part of the issue is that the VPN password is stored in an encrypted home folder, which is unavailable until a user is logged in, so it fails at start-up. So, I made crontab

I put greg's suggestion in a new script (/etc/NetworkManager/script.sh) after a 1-min delay:

sleep 60

nmcli con up id "MyVPNConnectionName"

I then added a crontab (crontab -e) that calls the script on start-up:

@reboot /bin/bash /etc/NetworkManager/script.sh

This is probably not the most elegant way to do it. It might mean a user has to log in within 60 seconds of start-up or the VPN connection will fail. Also, if you do anything online in the first 60 seconds, that won't go over the VPN. So... yeah, that's what I did.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .