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 Debian-based Linux such as Ubuntu, Mint, and Kali.
Initial Step: It is recommended to update the outdated packages on your system by running the update and upgrade commands according to the Linux distro in use.
Step #1: Run this command as root:
sudo nano /etc/default/openvpn
Now find and uncomment the following line (remove # next to the following line)
AUTOSTART="all"
Save the changes by pressing Ctrl+O and then close the file by pressing Ctrl+X.
Note: If the file is blank then just paste the above line and save it.
Step #2: Enter into the OpenVPN directory.
cd /etc/openvpn
Step #3: 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 #4: 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 #5: 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 #6: Enter ls so all the FastestVPN server files in the directory will be listed.
Step #7: 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 #8: 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 #9: Create and edit a new text file called pass by entering:
sudo nano /etc/openvpn/pass
Step #10: 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 #11: Enter the following to rename your chosen server file to client.conf.
sudo cp /etc/openvpn/uk1-udp.ovpn /etc/openvpn/client.conf
Step #12: Enable the OpenVPN service
sudo systemctl enable [email protected]
Step #13: Reload the daemons.
sudo systemctl daemon-reload
Step #14: Start the OpenVPN service.
sudo service openvpn@client start
Step #15: 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.
If the OpenVPN service was successfully started but the curl output still shows your actual IP and location, then create the OpenVPN logs file as given at the end of this guide and read the logs to determine the issue.
Disconnect OpenVPN
To stop or disconnect from OpenVPN, run the following command:
sudo service openvpn@client stop
Similarly, restart the service when needed by running the start command.
Creating OpenVPN Logs File:
To check the issues with OpenVPN connectivity, create an OpenVPN log file to check the connection and error logs.
Edit your VPN configuration file by running:
sudo nano /etc/openvpn/client.conf
In the file, add the following line and save it:
log-append /var/log/openvpn.log
That means an OpenVPN logs file called openvpn.log will be created in the /var/log directory.
Run the OpenVPN service again to generate fresh logs.
sudo service openvpn@client start
Now run curl ipinfo.io or curl ifconfig.co. In case you still see your actual IP/ location, read the OpenVPN logs from your created logs file by running:
sudo cat /etc/var/log/openvpn.log