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.
#!/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).
Normally enabled gateway monitoring also restarts OpenVPN. Did you not enable it?
Cheers,
Franco
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?
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