Smooth switching of VPN client node/server over SSH on Padvan RT-N56U

  • ATTENTION! As of November 1, 2020, you are not able to reply to threads 6 months after the thread is opened if there are more than 500 posts in the thread.
    Threads will not be locked, so posts may still be edited by their authors.
    Just start a new thread on the topic to post if you get an error message when trying to reply to a thread.


New Around Here
My first post - thank you to everyone here who has shared their knowledge.
I would like to share a very elegant way of switching router VPN client exit node between countries/servers.

I'm on Padavan with VPN Unlimited as provider using OpenVPN on a RT-N56U

First, get your VPN Client configured and connected to your VPN provider with parameters, certificates and keys using the regular RT-N56U/Padavan Admin Interface.

Then using a terminal connect to router over SSH (ssh [email protected] or your router IP).
Enable router SSH access in admin interface under administration / Services / SSH.
If you generate a SSH key pair you don't have to log in with password every time which is safer.

Locate the routers OpenVPN config file /etc/openvpn/client/client.conf
Copy it to your home directory (/opt/home/admin) as vpnloader.cfg using
cp /etc/openvpn/client/client.conf /opt/home/admin/vpnloader.cfg

In vpnloader.cfg find the node/server prefix and replace it with xx
For VPN unlimited it is "" which we replace with ""
You can edit the file with vi (vi vpnloader.cfg) or install joe editor which is a little friendlier.

Now we need the switching script below
- takes the template vpnloader.cfg and replaces the "xx" with requested server (using sed, the Stream editor command )
- writes this as a config file activevpn.cfg
- Kills current OpenVPN session
- lanches new openVPN session with this configuration.

I have options for Sweden/Finland/UK/USA/etc - add and edit them in the CASE statement.

Save this file as /opt/home/admin/ and make it executable (chmod +x /opt/home/admin/

case "$1"
se) echo Switching to Sweden
fi) echo Switching to Finland
lu) echo Switching to Luxembourg p2p
uk) echo Switching to UK
ro) echo Switching to Romania, p2p
us) echo Switching to USA
 *) echo No server specified: se, fi, lu, uk, ro, us

echo Killing current session
kill $(pgrep openvpn)

echo Writing config for $node
echo -e "$(sed "s/xx.vpnunlimited/$node.vpnunlimited/" vpnloader.cfg)" > /opt/home/admin/activevpn.cfg
openvpn --config /opt/home/admin/activevpn.cfg --daemon openvpn-cli --cd /etc/openvpn/client

A shortcut is helpful so edit the .profile file in home directory (vi ~/.profile) and add the line 'alias vpn=/opt/home/admin/' Log out and log in again to enable this alias.

Now you can switch VPN server by typing "vpn uk". The script will write a UK config and launch openvpn with that config file. Just typing VPN should give you the help text "No server specified: se, fi, lu, uk, ro, us"

You can now switch server/node by logging in to router over SSH, type "VPN fi" and.. done!

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!