The perks of having an automatic VPN connection are many. But notably, it will keep your Internet traffic private. The newer systemd Linux forces us to configure our startup script for OpenVPN to make it work. This guide depends on this OpenVPN setup. Learn how to configure OpenVPN to autostart on systemd Linux! [Read: Guide: Configure OpenVPN autostart Linux connection]
Table of Contents
Requirements for OpenVPN autostart on systemd Linux
Before you begin setting up OpenVPN to autostart on systemd Linux, you'll need a few prerequisites:
- OpenVPN
- A VPN provider
- A Linux distribution (distro) with systemd it could be Debian 8 or newer (I will be using OpenVPN on OSMC, which is Debian-based)
Configure OpenVPN for systemd Linux
Now, let's configure OpenVPN to autostart for systemd Linux. First open a terminal. We need to change the default behavior of OpenVPN. With the editor Nano, run the command:
sudo nano /etc/default/openvpn
Remove the '#' infront of 'AUTOSTART="all"' so that OpenVpn allows to start the .conf files. After that press "Ctrl X" to exit Nano and answer "Y" to save the file.
Run the following commands to show a list of possible vpn.ovpn files:
cd /etc/openvpn ls
Next, you need to decide which vpn.ovpn file you are going to auto connect to. The one you pick needs to be renamed to client.conf, because that's the standard way of doing it in the OpenVPN world. Run this command:
sudo cp vpnserver.ovpn client.conf
Where it says "vpnserver.ovpn" replace it with an existing file, the name will differ from provider to provider. For example, us123.nordvpn.com.tcp443.ovpn if you're using a VPN which requires you to login, like NordVPN does. Use this fix:
sudo nano client.conf
Change the line that says:
auth-users-pass
to:
auth-users-pass .secrets
Press "Ctrl X" and "Y" in order to save your changes.
sudo nano .secrets
Insert your username on the first line and password one the second then "Ctrl X" and "Y" to save the file.
username
password
Surfshark VPN Exclusive Offer - 82% off ($2.39/month):
♦ Hide your browsing (no logs), Anonymize Streaming and Downloads
♦ Wireguard Protocol support for VPN.
♦ Circumvent Geo/Country Restrictions and access worldwide content
♦ Works on Windows, Mac, Linux, Android, iOS, Router, and more
♦ 1 TB Encrypted Storage
♦ Money back guarantee - Sign Up Now
OpenVPN for systemd Linux: Enable the systemd service
Run the following command to enable the OpenVPN service to run while booting:
sudo systemctl enable [email protected]
Reload the daemons:
sudo systemctl daemon-reload
Start OpenVPN with the following command:
sudo service openvpn start
or
sudo systemctl start [email protected]
Stop OpenVPN with the following command:
sudo service openvpn stop
or
sudo systemctl stop [email protected]
Now it's time to test if it worked. Reboot the system with the command:
reboot
To check the external IP run the command:
curl ipinfo.io
If ipinfo.io
returns your VPN's external ip, you're done!
Configure OpenVPN to autostart using Linux: Final thoughts
That's how to set up OpenVPN autostart on systemd Linux. VPNs are available for multiple platforms and devices. IPVanish VPN is compatible with Fire TV devices. You can also install OpenVPN using Docker for a private VPN server. Considering a VPN? Learn if a VPN or DNS is right for you.
Which VPNs do you recommend, and which Linux ditros are you using them on?