LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-04-2014, 04:25 AM   #1
tonj
Member
 
Registered: Sep 2008
Posts: 546

Rep: Reputation: 37
auto-reconnect vpn tunnel?


I have a centos 6.5 server 64bit running openvpn-2.3.2-2.el6.x86_64 as a client, and it connects to a vpn service on the internet. I use this machine as a proxy server for all my computers and they surf the internet through the vpn tunnel.
The problem is the vpn tunnel goes down at random and I want to know if there's a way auto-reconnect it when it goes down. I've written a little script called reset.sh which always works in re-connecting the vpn tunnel but I have to run it myself. I'd like the server to run this script automatically however the server needs a way to 'know' that the vpn tunnel has gone down and then run the reset.sh script. Is this possible? is there a program that will cater for this?
 
Old 04-04-2014, 01:21 PM   #2
pingu
Senior Member
 
Registered: Jul 2004
Location: Skuttunge SWEDEN
Distribution: Debian preferably
Posts: 1,350

Rep: Reputation: 127Reputation: 127
I don't know of any program to handle this, but you could write a small shell script.
My first thought is you could check the existence of tunnel with "ifconfig" or "ip addr", and greping for an ip in correct range. If that ip doesn't exist then the script calls reset.sh.
Then run that as a cron job - you could set it to run every minute or whatever interval you choose.
 
Old 04-07-2014, 09:34 AM   #3
tonj
Member
 
Registered: Sep 2008
Posts: 546

Original Poster
Rep: Reputation: 37
so ironic. I've been waiting a few days now for the vpn tunnel to go down so I can inspect the logs, see what they say and try what you said but the connection has been solid.
 
Old 04-22-2014, 03:10 AM   #4
tonj
Member
 
Registered: Sep 2008
Posts: 546

Original Poster
Rep: Reputation: 37
I found a solution to this that may benefit others who have the same problem....
First you need to make sure openvpn is keeping its own log, which in my case is /home/share/openvpn-client.log.
then...
Install monit.
In the monit control file I have this:
check file openvpn-client.log with path /home/share/openvpn-client.log
if match "RESOLVE: Cannot resolve host address" then exec "/root/reset.sh"


reset.sh is a little script I wrote to reconnect my vpn but a normal user could replace /root/reset.sh with /etc/init.d/openvpn restart

this solution is working fine and it has already reconnected my vpn twice while I was away from the pc. From the time the vpn tunnel goes down it takes about 2 mins for the above process to get it back up again.

Last edited by tonj; 04-22-2014 at 03:57 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
DISCUSSION: Forward ports via an SSH tunnel with auto reconnect (using key pair authentication) merize147 LinuxAnswers Discussion 0 07-24-2006 04:31 PM
pftpfxp auto reconnect behade Linux - Software 4 01-12-2005 10:25 AM
ISP auto reconnect problem lumpfish Linux - Networking 0 07-29-2003 10:43 AM
Auto-Reconnect JC404 Linux - Newbie 3 07-01-2003 04:04 PM
want auto-reconnect off in wvdial marlaina1 Linux - General 2 03-18-2002 04:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration