Keep VPN Alive On Ubuntu

Overview

I have tried VPNs in the past but for whatever reason they always disconnect after a certain amount of time despite selecting automatically connect. I found a post on how to keep a VPN alive by using network manger command line and cron to schedule the command.

Pre-Requisite

Make sure a VPN connection is configured (beyond the scope of this post) using the Ubuntu network manager and ensure it works. It’s best to give the VPN a name without spaces.

Test

The first step is to test the setup of the VPN is correct as well as checking the command works. Make sure the VPN is disconnected.
nmcli con up id [myVpn]
where [myVpn] should be replaced with the name of the VPN connection. If the VPN connects after running the command then the test was sucessful.

Setup

Login as the user who requires the VPN connection.

Edit crontab:
crontab -e

Append the following entry replacing [myVpn] with the name of the VPN connection:
* * * * * /usr/bin/nmcli con up id [myVpn]

The above will run every minute but it can be changed to any frequency (see man crontab)

Summary

I’ve been running this for few days and the VPN connection seems stable enough to leave it running.

Always on VPN connection

About Danny

I.T software professional always studying and applying the knowledge gained and one way of doing this is to blog. Danny also has participates in a part time project called Energy@Home [http://code.google.com/p/energyathome/] for monitoring energy usage on a premise. Dedicated to I.T since studying pure Information Technology since the age of 16, Danny Tsang working in the field that he has aimed for since leaving school. View all posts by Danny → This entry was posted in Linux, Networking and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *.

All comments must go through an approval and anti-spam process before appearing on the website. Please be patience and do not re-submit your comment if it does not appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.