Autostart OpenVPN On Linux
- This tutorial explains how to autostart OpenVPN in a Linux systemd.
- After these steps, your OpenVPN will be auto-connected after a system reboot. Moreover, you can also use this setup to connect/ disconnect OpenVPN with a single command whenever needed.
- The following tutorial is applicable to Red Hat based Linux such as Fedora and CentOS
Step #1: Enter into the OpenVPN directory.
cd /etc/openvpn
Step #2: Download FastestVPN’s OpenVPN server config files by running these commands.
sudo wget http://support.fastestvpn.com/download/fastestvpn_ovpn/ -O fastestvpn_ovpn.zip
Step #3: Unzip the downloaded files as root.
sudo unzip fastestvpn_ovpn.zip
Note: If it says that “unzip command not found” then install unzip by entering apt install unzip and follow Step # 4 again.
Step #4: Now copy the unzipped server files into the OpenVPN directory.
cp /etc/openvpn/tcp_files/* /etc/openvpn/ && cp /etc/openvpn/udp_files/* /etc/openvpn/
Step #5: Enter ls so all the FastestVPN server files in the directory will be listed.
Step #6: Choose your desired VPN server file which you want to connect on autostart. For example uk1-udp.ovpn in this case. Edit this file by entering:
sudo nano uk1-udp.ovpn
Step #7: Find the line auth-user-pass and change it to auth-user-pass pass
Save the changes by pressing Ctrl+O and then close the file by pressing Ctrl+X.
Step #8: Create and edit a new text file called pass by entering:
sudo nano /etc/openvpn/client/pass
Step #9: In the file, enter your FastestVPN username on the first line and password on the second line. Make sure to enter the precise info and no space characters should be left at the beginning and end of the text.
Save the changes by pressing Ctrl+O and then close the file by pressing Ctrl+X.
Step #10: Enter the following to rename your chosen server file to client.conf.
sudo cp /etc/openvpn/uk1-udp.ovpn /etc/openvpn/client.conf
Step #11: Enable the OpenVPN service
sudo systemctl enable [email protected]
Step #12: Reload the daemons.
sudo systemctl daemon-reload
Step #13: Start the OpenVPN service.
sudo service [email protected] start
Step #14: Wait for a few seconds and check the VPN connectivity by running the following command and it should show the VPN server’s IP and location.
curl ipinfo.io
Note: If it says that “curl command not found” then install it by entering apt install curl and follow Step # 15 again.
In case of a successful connection, OpenVPN should auto-connect after a system reboot. Run the curl ipinfo.io or curl ifconfig.co command to test the VPN connectivity after a reboot.
Disconnect OpenVPN
To stop the OpenVPN until the next reboot:
sudo service openvpn@client stop
To permanently disable the OpenVPN service:
sudo systemctl disable [email protected] sudo service openvpn@client stop
Similarly, restart the service when needed by running the enable and start commands as given in Steps 11-13.