How to use more than one VPN server on OpenWrt?

Hello all
I have a question: Is it possible to add more than one vpn server, for example nord, add more than one server with the .ovpn extension, then openwrt chooses one of the servers to connect to automatically (not manually) and chooses randomly in case you want to use a vpn?

I mean, I succeeded in installing and setting up the openwrt system on the router and making the VPN settings. I used one file to connect, which is us_california-aes-128-cbc-udp-dns.ovpn
But I don't want to be limited to this server, I just want to get all the servers in my nord account
It is easy in the manual way, but I want it to be automatic without having to go into the openwrt settings and replace the file us_california-aes-128-cbc-udp-dns.ovpn with another file!

All love to you

Rotate the ovpn files, randomly on every boot, or more often, using cron?


Just create them as different OpenVPN interfaces. I am using a couple of interfaces of different VPN-protocols at the same time, the problem is as always there can only be one default gateway.

Then you can use mwan3 to balance between them or for examply vpn-policy-routing to for example have different outgoing OpenVPN connections for different clients:


Thank you for your reply
But how is it appropriate to do so?
Did you use the rename command, for example?

Create a softlink, pointing to an ovpn file, then just move the softlink pointer between files, always using the same name.

In openwrt point to the softlink file.

1 Like

Thank you for the reply sir
i beg your pardon
First: Can you explain this using commands, and I think that is what is meant, but how is that?
Assuming I have these files inside openvpn /etc/openvpn folder
..... 100.ovpn

Where can I create a soft link?

secondly : how move the softlink pointer between files ?

big thanks
best regards

Where the real ones are?

ln -s 1.ovpn default.ovpn
rm default.ovpn
ln -s 2.ovpn default.ovpn

Always point to default.ovpn when setting up the VPN client.

1 Like

'ln' instead of 'ls'

1 Like

Thnx, you're very right, fixed.

1 Like

You can generate random number with awk:

awk 'BEGIN{srand();print int(rand()*(63000-2000))+2000}'

You can fill array from ls *.ovpn, after that choose random file for soft link.


I greatly appreciate your advice
I would like to add another idea , you can use the rename commands inside the cron instead of the delete command:
mv 1.ovpn default.ovpn
mv default.ovpn 1.ovpn
mv 2.ovpn default.ovpn
mv default.ovpn 2.ovpn

best regards

big thanks sir
After creating a random number, what can I benefit from it?
Can you enhance the explanation with commands?
Assuming I have files :

..... 100.ovpn

Given that the default name I use is : default.ovpn

Thank you very much for help

yes you can, but you want to cp -f instead of mv, since you always want to have the source ovpn file intact.

Sorry, bash from Busybox does not understand arrays.

However it works for special case, where n is randomly selected from 1 to 100.

n=$(awk 'BEGIN{srand();print int(rand()*(100))+1}')
ln -s $n.ovpn default.ovpn
service openvpn restart
service network restart
1 Like

sweet solution.

probably want to add a rm -f default.ovpn before the ln -s though.

1 Like

Just out of curiosity, how often are you intending to switch VPN servers? Every five minutes? What would be the use of it?

The ln has a -f option to over existing files which you could use instead of an rm.

So instead of rm -f default.ovpn ; ln -s $n.ovpn default.ovpn you could simply use ln -sf $n.ovpn default.ovpn.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.