Random and rotating OpenVPN or WireGuard connection

Hello,

I would like to use my OpenWRT router as a gateway for all devices connected to it.

All traffic should be routed via a VPN connection. This is not a problem so far.

Is there a way to establish this VPN connection daily to a random VPN server (several config files available)? The whole process should be automated.

Many thanks in advance and best regards,
Frank

rotate the config, restart the connection ?
schedule the whole thing in cron.

2 Likes

For openvpn random connection to a server can be set in the openvpn config, the only thing to do is a cron job restarting OpenVPN daily

For random connection add multiple server lines in the OpenVPN config and add

server-poll-timeout 10
remote-random
remote [server address1] [port number]
remote [server address2] [port number]
remote [server address3] [port number]

From the DDWRT OpenVPN Client setup guide:

Some VPN providers use the same keys for multiple servers/countries you can then alternate between countries or add extra servers if the first one is not working with
server-poll-timeout 10
remote-random
remote [server address] [port number]
remote de.vpnunlimitedapp.com 1194

server poll timeout will query for 10 seconds before querying the next, remote random will randomly choose the first server to query if you remove this it will query your list from top to bottom

For WireGuard you have to script this yourself a starting point might me the WireGuard Watchdog with fail over:

Or the WireGuard Companion:

2 Likes

Thank you very much. With OpenVPN and the random server it works wonderfully.

Do you have any information on how to restart OpenVPN correctly with the cron job?

Try:
service openvpn restart

Edit: for cron see: https://openwrt.org/docs/guide-user/base-system/cron

P.S.
If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.
Thanks! :slight_smile:

2 Likes