Home » Home Media » Guide: Configure OpenVPN to autostart on systemd Linux

Guide: Configure OpenVPN to autostart on systemd Linux

Configure OpenVPN autostart Linux image

written by Jens July 24, 2017

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]

Requirements for OpenVPN autostart on systemd Linux

Before you begin setting up OpenVPN to autostart on systemd Linux, you’ll need a few prerequisites:

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.

configure openvpn to autostart - Systemd Linux

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

IPVanish VPN Exclusive Offer - only $3.25/month:

VPN Guides
Windows, Android, Ubuntu
Kodi OpenVPN
OSMC on RPi

♦ Hide your browsing (no logs), Anonymize Streaming and Downloads
♦ Circumvent Geo/Country Restrictions and access worldwide content
♦ Works on Windows, Mac, Linux, Android, iOS, Router, and more
♦ 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 openvpn@client.service

Reload the daemons:

sudo systemctl daemon-reload

Start OpenVPN with the following command:

sudo service openvpn start

or

sudo systemctl start openvpn@client.service

Stop OpenVPN with the following command:

sudo service openvpn stop

or

sudo systemctl stop openvpn@client.service

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?

IPVanish VPN Exclusive Offer - only $3.25/month:
VPN Guides
Windows, Android, Ubuntu
Kodi OpenVPN
OSMC on RPi
♦ Hide your browsing (no logs), Anonymize Streaming and Downloads
♦ Circumvent Geo/Country Restrictions and access worldwide content
♦ Works on Windows, Mac, Linux, Android, iOS, Router, and more
♦ Money back guarantee - Sign Up Now

Related Articles