Ask Your Question

How to start Openvpn service at boot time

asked 2013-02-22 09:29:02 -0500

Cerin gravatar image

updated 2013-03-04 10:34:39 -0500

How do you configure the openvpn service to start when the computer boots?

Based on some other answers (which this board won't let me post links to apparently), this should simply be:

systemctl enable openvpn@server.service

but this just returns:

Failed to issue method call: No such file or directory

I can start/stop/find status of the service using

systemctl start openvpn@server.service
systemctl stop openvpn@server.service
systemctl status openvpn@server.service

I've also tried:

systemctl enable openvpn@service
systemctl enable openvpn.service

but these also result in "Failed to issue method call: No such file or directory"

[user@localhost ~]# systemctl|grep vpn
openvpn@...i-user.service loaded failed failed        OpenVPN Robust And Highly Flexible Tunneling Application On multi/user
openvpn@server.service    loaded active running       OpenVPN Robust And Highly Flexible Tunneling Application On server
[user@localhost ~]# rpm -qs openvpn|grep service
normal        /lib/systemd/system/openvpn@.service

[user@localhost ~]# ll /etc/openvpn
total 68
-rwxr-xr-x 1 root root   772 Jul 18  2011 bridge-start
-rwxr-xr-x 1 root root   316 Jul 18  2011 bridge-stop
-rw-r--r-- 1 root root    67 Jul 18  2011
-rw-r--r-- 1 root root    56 Jul 18  2011
drwxr-xr-x 4 root root  4096 Oct 19  2010 easy-rsa
-rw------- 1 root root   180 Feb 22 11:05 ipp.txt
drwx------ 2 root root  4096 Jan 22 10:49 keys
-rwxr-xr-x 1 root root   509 Jul 18  2011 nat-startup
-rwxr-xr-x 1 root root    45 Jul 18  2011 openvpn-shutdown
-rwxr-xr-x 1 root root    46 Jul 18  2011 openvpn-startup
-rw------- 1 root root   369 Feb 22 11:08 openvpn-status.log
-rw-r--r-- 1 root root 10916 Oct 10  2011 server.conf
-rw-r--r-- 1 root root 10562 Jul 18  2011 server.conf.orig

Showing successfully enabling and starting the service, rebooting, and then showing the service did not start:

[user@localhost ~]# ssh user@host
[user@host ~]# sudo systemctl status openvpn@server.service
openvpn@server.service - OpenVPN Robust And Highly Flexible Tunneling Application On server
      Loaded: loaded (/lib/systemd/system/openvpn@.service; enabled)
      Active: inactive (dead)
      CGroup: name=systemd:/system/openvpn@.service/server
[user@host ~]# sudo systemctl start openvpn@server.service
[user@host ~]# sudo systemctl status openvpn@server.service
openvpn@server.service - OpenVPN Robust And Highly Flexible Tunneling Application On server
      Loaded: loaded (/lib/systemd/system/openvpn@.service; enabled)
      Active: active (running) since Mon, 04 Mar 2013 11:22:14 -0500; 16s ago
     Process: 20585 ExecStart=/usr/sbin/openvpn --daemon --writepid /var/run/openvpn/ --cd /etc/openvpn/ --config %i.conf (code=exited, status=0/SUCCESS)
    Main PID: 20586 (openvpn)
      CGroup: name=systemd:/system/openvpn@.service/server
          โ”” 20586 /usr/sbin/openvpn --daemon --writepid /var/run/openvpn/ --cd /etc/openvpn/ --config server.conf
[user@host ~]# sudo reboot

Broadcast message from user@host on pts/0 (Mon, 04 Mar 2013 11:23:01 -0500):

The system is going down for reboot NOW!

[user@localhost ~]# Connection to host closed by remote host.
[user@localhost ~]# ssh user@host
[user@host ~]# sudo systemctl status openvpn@server.service
openvpn@server ...
edit retag flag offensive close merge delete


Anything show up with systemctl|grep vpn or rpm -qs openvpn|grep service ?

randomuser gravatar imagerandomuser ( 2013-02-22 09:34:50 -0500 )edit

@randomuser, I've appended the output of those commands to my question.

Cerin gravatar imageCerin ( 2013-02-22 09:59:40 -0500 )edit

Also put the output of ll /etc/openvpn/

lnxslck gravatar imagelnxslck ( 2013-02-22 10:01:18 -0500 )edit

the '@' in a service name typically indicates a service that can run multiple instances. I can't think of how to enable one offhand, but perhaps this will point you in the right direction.

randomuser gravatar imagerandomuser ( 2013-02-22 10:02:53 -0500 )edit

@lnxslck, Done.

Cerin gravatar imageCerin ( 2013-02-22 10:12:31 -0500 )edit

5 Answers

Sort by ยป oldest newest most voted

answered 2013-03-04 13:02:50 -0500

Cerin gravatar image

It seems this is a known bug/limitation in the design of the Systemd framework in combination with OpenVPN. Since OpenVPN supports multiple servers, each daemon requires a separate configuration file, which Systemd does not support "out of the box". The solution is to create a /etc/systemd/system/<server>.service file for each openvpn <server>.conf file.

Mine looks like:

Description=OpenVPN Robust And Highly Flexible Tunneling Application On <server>

ExecStart=/usr/sbin/openvpn --daemon --writepid /var/run/openvpn/<server>.pid --cd /etc/openvpn/ --config <server>.conf


Replace <server> with the name of your configuration file.

Then, I simply call:

sudo systemctl enable <server>.service
sudo systemctl start <server>.service

After I rebooted, the service was started automatically.

edit flag offensive delete link more


Great info, this helped me soooo much. Last time I set up openvpn on fedora to connect at boot it took me forever to figure out, this time 10mins. I did have an issue though where sometimes it would connect normally, sometimes it wouldn't connect at all, and sometimes it would connect twice. Turns out I had duplicate files, names slightly different, in I deleted one and everything works great. Thanks again

jbodhorn gravatar imagejbodhorn ( 2015-09-26 18:55:46 -0500 )edit

Hi there, I have recently started using Linux and am now trying to configure my PIA VPN. I have configured my PIA VPN and can now run it manually, but can't get it to work to run on boot.

When installing, I had to handle a ".ca" file (certificate, from what I understood), however, I don't have or can't find a <server>.conf file. Therefore, I can't follow the above directions.

I would be most grateful if you could help me with this!

edit: I am using Fedora 23 and the only file I have in /etc/openvpn is a ca.crt file.

rxis gravatar imagerxis ( 2016-03-29 03:40:15 -0500 )edit

answered 2017-07-21 16:26:50 -0500

rhcev6 gravatar image

systemctl enable openvpn@server.service Created symlink /etc/systemd/system/ โ†’ /usr/lib/systemd/system/openvpn@.service.

the format of these multi-instance commands (for openvpn anyway) is openvpn@xxxxx.service where xxxxx -s the name of the config file. so for openvpn@server.service the config file is /etc/openvpn/server.conf. If I has a second config names /etc/openvpn/server2.conf then I would enable/disable/start/stop openvpn@server2.service

edit flag offensive delete link more

answered 2013-02-22 09:58:46 -0500

Aleksandar Kostadinov gravatar image

updated 2013-02-22 14:23:33 -0500

try (notice sudo):

$ sudo systemctl enable openvpn@.service
edit flag offensive delete link more


This makes sudo systemctl status openvpn@server.service list the service as "enabled", but it still fails to start and is still listed as "inactive (dead)" after a reboot.

Cerin gravatar imageCerin ( 2013-03-04 10:29:31 -0500 )edit

answered 2015-02-23 10:13:57 -0500

This works for me on Fedora 21 and Centos 7:

cd /etc/systemd/system/
ln -s /usr/lib/systemd/system/openvpn@.service openvpn@server.service
edit flag offensive delete link more

answered 2018-02-28 08:50:00 -0500

mikmik gravatar image

Systemd startscripts were bit changed in Fedora, but it seems it is not documented anywhere. The idea is that you could have multiple config files in /etc/openvpn/ directory and you can use systemd to start with different configs. For example assume you have got on config in /etc/openvpn/serverudp.conf and the other one /etc/openvpn/servertcp.conf, which differ only by having "proto udp" and "proto tcp".

Then you enable these services by:

systemctl enable openvpn-server@serverudp.service
systemctl enable openvpn-server@servertcp.service

You start them with these commands and they will use the respective config files:

systemctl start openvpn-server@serverudp.service
systemctl start openvpn-server@servertcp.service

Best regards

Michal Ambroz

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2013-02-22 09:29:02 -0500

Seen: 44,385 times

Last updated: Feb 28 '18