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.

kmhelander

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 3.4.3.9-099 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
Code:
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 "de.vpnunlimitedapp.com" which we replace with "xx.vpnunlimitedapp.com"
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 setvpn.sh below
It..
- 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/setvpn.sh and make it executable (chmod +x /opt/home/admin/setvpn.sh)

Code:
case "$1"
in
se) echo Switching to Sweden
    node=se;;
fi) echo Switching to Finland
    node=fi;;
lu) echo Switching to Luxembourg p2p
    node=lu;;
uk) echo Switching to UK
    node=uk;;
ro) echo Switching to Romania, p2p
    node=ro;;
us) echo Switching to USA
    node=us-ny;;
 *) echo No server specified: se, fi, lu, uk, ro, us
    exit;;
esac

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/setvpn.sh' 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!
Top