OPNsense Forum

Archive => 17.7 Legacy Series => Topic started by: ckishappy on September 11, 2017, 01:35:32 pm

Title: Cron Script for ping and restart of the opvn client every minute?
Post by: ckishappy on September 11, 2017, 01:35:32 pm
I just loaded opnsense on my old hp microserver Gen8 and opnsense is exactly what I was looking for. I get around 100Mbs with the OVPN client so will then buy some 1U decisio appliance soon to get some more speed with ovpn. I like the approach of the company.

Two questions:

1) I would like to run a cron script to ping an address every minute or so. If 6 pings fail, I would like to restart the ovpn client to ensure the client really reconnects to the vpn server. Please advise how I can do this?

2) I would like to run a cron script to see if the WAN is still up. If the WAN is down for more than a minute, I would like to restart the opensense server. Please advise how I can do this?

Title: Re: Cron Script for ping and restart of the opvn client every minute?
Post by: phoenix on September 11, 2017, 02:05:23 pm
There's a couple of posts of mine (and a script) that should give you some ideas in this thread: https://forum.opnsense.org/index.php?topic=5511.0;topicseen
Title: Re: Cron Script for ping and restart of the opvn client every minute?
Post by: ChrisH on September 11, 2017, 02:56:36 pm
OpenVPN already has --ping-restart, is that not enough?

And rebooting the whole box every minute because the WAN link is down seems a bit drastic to me...
Title: Re: Cron Script for ping and restart of the opvn client every minute?
Post by: ckishappy on September 11, 2017, 04:13:00 pm
Thanks you are right that the server reboot is a bit dramatic. I use indeed keepalive. The wan connection is quite stable but still restarting the ovpn connection typically avoids any manual intervention throughout the day, week, month, year.

Is there a script just for the ovpnclient restart? in the log this is called rc.newwanip starting ovpnc1.. Pls advise?
Title: Re: Cron Script for ping and restart of the opvn client every minute?
Post by: ckishappy on September 11, 2017, 04:14:31 pm
There's a couple of posts of mine (and a script) that should give you some ideas in this thread: https://forum.opnsense.org/index.php?topic=5511.0;topicseen

Thanks for the sample script, do you know the command for restarting the WAN with a fixed IP?

Title: Re: Cron Script for ping and restart of the opvn client every minute?
Post by: phoenix on September 11, 2017, 04:44:33 pm
Thanks for the sample script, do you know the command for restarting the WAN with a fixed IP?
If your ISP provides you with a fixed IP then the restarting the WAN interface will pick it up, I have a fixed IP on my internet connection. :) If you mean it's a specific IP that you have set then ifconfig can be used to set a specific IP in this format:

Code: [Select]
ifconfig vmx0  10.0.0.10/24