this post was submitted on 29 Jun 2023
1 points (66.7% liked)

VPN

951 readers
14 users here now

A community for VPN users and those who want to know more about them.

founded 2 years ago
MODERATORS
 

Since /etc/openvpn gets scanned on boot for .conf files to use openvpn to connect to, can I just rename all of my .ovpn files as .conf and it'll pick a random one each time (or at least go in alphabetical order until it finds one that works)?

top 1 comments
sorted by: hot top controversial new old
[–] [email protected] 2 points 2 years ago

Answered by ai.

No, renaming your .ovpn files as .conf will not make OpenVPN pick a random one or go in alphabetical order until it finds one that works. The scanning of /etc/openvpn directory on boot is performed by the OpenVPN service, and it expects the configuration files to have a .conf extension.

If you want to have OpenVPN pick a random or specific .ovpn file each time, you can create a single .conf file that includes the individual .ovpn files. Here's an example:

  1. Create a new file called random.ovpn.conf in /etc/openvpn directory.
  2. Edit random.ovpn.conf and add the following lines:
# Random OpenVPN Config
client
dev tun

# Randomly pick one of the .ovpn files
script-security 2
up /etc/openvpn/random.sh

# Additional OpenVPN configuration options can be added here

  1. Create a new file called random.sh in /etc/openvpn directory.
  2. Edit random.sh and add the following lines:
#!/bin/bashovpn_files=(/etc/openvpn/*.ovpn)
random_file=${ovpn_files[$RANDOM % ${#ovpn_files[@]}]}
/usr/sbin/openvpn --config "$random_file"

Make sure to set the correct permissions for the random.sh file using the command:

sudo chmod +x /etc/openvpn/random.sh```

With this setup, the random.sh script will randomly pick one of the .ovpn files in /etc/openvpn directory and pass it to the OpenVPN command. Each time you start the OpenVPN service, it will use a different .ovpn file.