DEV Community

Cover image for Force Reconnect OpenVPN client connections (commandline) on EdgeOS
Wietse Wind
Wietse Wind

Posted on

Force Reconnect OpenVPN client connections (commandline) on EdgeOS

If your EdgeOS router has one or more OpenVPN client connections configured, you may want to restart the OpenVPN connection at some point. Either because it is down and somehow doesn't come back and you want to force that, or because you simply want it to restart (and pick up new settings / IP / ...).

In the EdgeOS web interface you can simply disable and re enable the VPN interface, but on the commandline it's not that easy.

Let's say your OpenVPN client connection is vtun1. To restart the connection the easy way, simply create (you can do this the easy way after installing the nano text editor)a script somewhere (eg. in /config/scripts. Let's call it restart-ovpn.sh.

The contents of the restart-ovpn.sh file (assuming your SSH client connection is vtun1) should be:

#!/bin/bash
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper begin
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper set interfaces openvpn vtun1 disable
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper commit
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper delete interfaces openvpn vtun1 disable
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper commit
/opt/vyatta/sbin/vyatta-cfg-cmd-wrapper end
logger -t piareset openvpn restarted
Enter fullscreen mode Exit fullscreen mode

This scripts start a config session, disables the OpenVPN client, commits, deletes the disable flag, commits again, ends the config session and then writes a logline (for future reference).

You can now make the script executable:

chmod +x restart-ovpn.sh
Enter fullscreen mode Exit fullscreen mode

... and the next time you want to restart your OpenVPN client connection on the commandline, simply run (from the folder where you created the restart-ovpn.sh file):

./restart-ovpn.sh
Enter fullscreen mode Exit fullscreen mode

Top comments (0)