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)?
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:
- Create a new file called random.ovpn.conf in /etc/openvpn directory.
- 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
- Create a new file called random.sh in /etc/openvpn directory.
- 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.