User Tools

Site Tools


synologyopenvpnautoreconnect

Synology: OpenVPN client: Auto reconnect via script with Tux

Hey, my name is "Tux"! Did you ever wonder how you can set up your Synology NAS' OpenVPN client to automatic reconnect to a lost OpenVPN server connection?

Hey, my name is "Tux" and this tutorial will show you how you can configure an automatic reconnection of your Synology NAS OpenVPN client after the connection to its OpenVPN server got lost.



First thoughts

Note

This tutorial assumes that you already have set up a working OpenVPN connection between your Synology NAS' OpenVPN client and the according OpenVPN server!


Start of tutorial

First of all make sure the OpenVPN connection is disconnected. Now open an SSH session with your local computer to your Synology NAS and prepare the following command (just prepare it but don't execute it yet!):

$ cat /usr/syno/etc/synovpnclient/vpnc_connecting

Now establish the OpenVPN connection and execute the prepared command simultaneously.

Explanation: During connection establishment the OpenVPN client creates temporarly a file called /usr/syno/etc/synovpnclient/vpnc_connecting and holds it for a few seconds. This file contains an unique connection ID and other informations required for following steps in this tutorial.
The output should look like this:

conf_id=<myConnectionID>
conf_name=<myConnectionDescription>
proto=<myVPNType>


Now change to root user:

$ sudo -i

Create the following script file…

$ vi /root/connectVPN.sh

…and add the following content:

#!/bin/sh
ID=<myConnectionID>
cat >/usr/syno/etc/synovpnclient/vpnc_connecting <<END
conf_id=$ID
conf_name=<myConnectionDescription>
proto=openvpn
END
synovpnc connect --id=$ID

Save the file and quit the editor.

Now make the script executable:

$ chmod +x /root/connectVPN.sh

Now you can set up an according job via DSM's Task Scheduler which runs the script on according intervals as you prefer.


End of tutorial

synologyopenvpnautoreconnect.txt · Last modified: 2023/04/22