Page 1 of 1

Random OVPN selection on startup

Posted: Sat Mar 23, 2019 6:37 pm
by SkyChaser
I plan to have OpenVPN autostart on boot (linux), but for obvious reasons, it's desirable to not always use the same server every time you connect to your VPN. Problem is each server has its own .OVPN file, and if i want to change server at every startup, then i would have to change the .OVPN file path every time, meaning i cant really "autostart"

Is there a way to tell OpenVPN to just pick a random .OVPN config file at startup?
Possibly any .OVPN file in specified folder?
Example.
>Have folder /etc/openvpn/USservers
>Set OpenVPN to autostart on boot
>OpenVPN starts & selects random .OVPN file
>Connects

Possible?
(Using CLI not GUI)

OR,
is it possible to put ALL US servers in one .OVPN file, and having OpenVPN randomly select a server IP from inside that file?
Thanks :mrgreen:

Re: Random OVPN selection on startup

Posted: Mon Mar 25, 2019 3:20 pm
by TinCanTech
SkyChaser wrote:
Sat Mar 23, 2019 6:37 pm
Is there a way to tell OpenVPN to just pick a random .OVPN config file at startup?
Not with openvpn itself but your OS could probably manage this with a script.
SkyChaser wrote:
Sat Mar 23, 2019 6:37 pm
is it possible to put ALL US servers in one .OVPN file, and having OpenVPN randomly select a server IP from inside that file?
No, this is not possible. Openvpn allows only one client certificate+key per config.

Re: Random OVPN selection on startup

Posted: Wed Mar 27, 2019 3:24 am
by SkyChaser
TinCanTech wrote:
Mon Mar 25, 2019 3:20 pm
SkyChaser wrote:
Sat Mar 23, 2019 6:37 pm
Is there a way to tell OpenVPN to just pick a random .OVPN config file at startup?
Not with openvpn itself but your OS could probably manage this with a script.
Thanks for the reply,
Im using a debian based version of linux (antix) without GUI to run my vpn.
As a novice linux user, where could i learn about the relevant scripting to make this possilbe?
which config file needs editing?
would really love some code i could copy paste.
im sure others could benifit from this too.
SkyChaser wrote:
Sat Mar 23, 2019 6:37 pm
SkyChaser wrote:
Sat Mar 23, 2019 6:37 pm
is it possible to put ALL US servers in one .OVPN file, and having OpenVPN randomly select a server IP from inside that file?
No, this is not possible. Openvpn allows only one client certificate+key per config.
from my inspection of various OVPN files, the certificate and static key in each file appear to be identical?
the only detail that cahnged is the "remote IP" (port number remains the same also)
Still not possible?

Also, i know about the trick of putting an "Auth.txt" in the .OVPN file to save entering creditials on startup,
however as my VPN provider has +1000 OVPN files, it's unfeasible to enter "Auth.txt" in every file.
Is there a way to give OpenVPN credentials without editing every .OVPN?

thank you

Re: Random OVPN selection on startup

Posted: Fri Apr 26, 2019 6:40 pm
by homedev
actually... maybe.
re-read above, you can only put one key/cert ect per file, but the "remote my-server-1 1194" line is an ordered line. meaning that if "my-server-1" fails it will try the next remote line but with the same credentials.

i use this for my home vpn as such,

remote 192.168.0.1 1194
remote 192.168.1.1 1194
remote NAME.hopto.org 1194


this will try to contact the server at *.0.1 first
if that times out it goes to *.1.1
if that times out that means we are not at home and uses the ddns link.

while I connect to one server, if all the servers have the same setup and credentials etc, you can use this method to connect to the vpn sequentially, its not the random question/answer pair you wanted, but it should help stabilize the config if the VPN company turns off one server.

Re: Random OVPN selection on startup

Posted: Mon May 27, 2019 12:05 am
by d2t93y7c
SkyChaser wrote:
Sat Mar 23, 2019 6:37 pm
Is there a way to tell OpenVPN to just pick a random .OVPN config file at startup?
The script (should have randomness one day) near the bottom of topic:Linux client login script question or if you can't wait then do a search for "bash random" to write your own script.
SkyChaser wrote:
Sat Mar 23, 2019 6:37 pm
is it possible to put ALL US servers in one .OVPN file, and having OpenVPN randomly select a server IP from inside that file?
Yes, you can put all servers in one file and randomly select a server IP from inside that file:

Code: Select all

remote 1.2.3.4
remote 1.2.3.4
remote 1.2.3.4

remote-random
I presume all of the certificate info is the same.