OPNsense Forum

Archive => 18.7 Legacy Series => Topic started by: bgp12 on June 08, 2018, 02:11:04 am

Title: Reconnect OpenVPN client
Post by: bgp12 on June 08, 2018, 02:11:04 am
Hi All!

I was having a problem with my openvpn client not reconnecting after a dropped connection and searched around for a simple solution. Not much info (for V18.x) but was able to find all of the info in various places around the net.

Thanks to this site (https://zercle.tech/2017/pfsense-openvpn-client-auto-reconnect/) for the basic instructions.

Code: [Select]
#!/usr/bin/env sh
VPNSRCIP="$(/sbin/ifconfig ovpnc1 | grep 'inet ' | cut -f1 -d '-' | awk '{ print $2}')"
VPNGWIP="$(/sbin/ifconfig ovpnc1 | grep 'inet ' | cut -d ' ' -f 4)"
if /sbin/ping -S "${VPNSRCIP}" -c 3 "${VPNGWIP}"; then
    # Success, Nothing to do
    exit 0
else
    # Fail, Reconnect VPN
    configctl openvpn reload
fi

exit 1

I have a basic OpenVPN client setup that connects to a random server, so this snippet works well with my config.

It would be nice to see a simple feature to click a checkbox to do gateway monitoring in the client settings.

Hope this helps with auto-reconnecting an OpenVPN client or for restarting the OpenVPN service (both well hidden online and in the forums).
Title: Re: Reconnect OpenVPN client
Post by: franco on June 12, 2018, 09:47:28 am
Normally enabled gateway monitoring also restarts OpenVPN. Did you not enable it?


Cheers,
Franco
Title: Re: Reconnect OpenVPN client
Post by: bgp12 on June 21, 2018, 08:42:34 pm
Thank you! Yes. GW monitoring is/was set to see RTT thru the connection.

Also, is there a way to use configctl openvpn reload to only restart a specific client, instead of the service?
Title: Re: Reconnect OpenVPN client
Post by: franco on June 22, 2018, 11:23:15 am
Yes and no. The way it's currently set up is to pass a Gateway Name to the script to figure out which clients require restarting. But if you only have one Gateway it always restarts all your clients. Restart by instance only works from the GUI at this point.


Cheers,
Franco