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 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?

share|improve this question

3 Answers 3

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer
    
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 Jul 25 '12 at 14:41

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.