OpenVPN, moving from init.d way to the Stretch/systemd way

While your solution might work for you, I’d be remiss if I didn’t provide an alternative – and simpler – method, as least as far as the CLI side is concerned.

If you want openvpn to start automatically at system boot, run this command

sudo systemctl enable openvpn

To switch it off, it’s simply:

sudo systemctl disable openvpn

Place your VPN provider’s configuration file in /etc/openvpn (using sudo). Ditto any certificates, etc. Ensure that the configuration files is <something>.conf, not <something>.ovpn.

Edit file /etc/default/openvpn and append the name of the .conf file you want to run to the AUTOSTART= line, less the .conf part. So for myvpn.conf it would read AUTOSTART=myvpn.

If you want to run a VPN configuration that’s not defined as AUTOSTART, but has a config file in /etc/openvpn, you can start/stop it with

sudo systemctl start openvpn@myvpn2
sudo systemctl stop openvpn@myvpn2

And for good measure, install openresolv, rather than resolvconf.

Edit: Fixed an error. Thx @zilexa

1 Like