OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • Archive »
  • 18.7 Legacy Series »
  • Reconnect OpenVPN client
« previous next »
  • Print
Pages: [1]

Author Topic: Reconnect OpenVPN client  (Read 4422 times)

bgp12

  • Newbie
  • *
  • Posts: 2
  • Karma: 1
    • View Profile
Reconnect OpenVPN client
« 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 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).
« Last Edit: June 08, 2018, 02:15:45 am by bgp12 »
Logged

franco

  • Administrator
  • Hero Member
  • *****
  • Posts: 13609
  • Karma: 1170
    • View Profile
Re: Reconnect OpenVPN client
« Reply #1 on: June 12, 2018, 09:47:28 am »
Normally enabled gateway monitoring also restarts OpenVPN. Did you not enable it?


Cheers,
Franco
Logged

bgp12

  • Newbie
  • *
  • Posts: 2
  • Karma: 1
    • View Profile
Re: Reconnect OpenVPN client
« Reply #2 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?
Logged

franco

  • Administrator
  • Hero Member
  • *****
  • Posts: 13609
  • Karma: 1170
    • View Profile
Re: Reconnect OpenVPN client
« Reply #3 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
Logged

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • Archive »
  • 18.7 Legacy Series »
  • Reconnect OpenVPN client
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2023 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2