12

I installed and oepnvpn on an Ubuntu server 16.04 by following the following guideline how-to-set-up-an-openvpn-server-on-ubuntu

When I start the openVPN server with: service openvpn start it looks like it get started, but I get no log files written even though I have the log option activated.

status /var/log/openvpn-status.log
log  /var/log/openvpn.log    

Any hints what I can try?

  • how can I check if the process/service is really running?
  • how can I find out if the service is crashing every time?
  • any idea why the log files don't get written?

output on starting the service

root@Diabolo:/etc/openvpn# service openvpn stop
root@Diabolo:/etc/openvpn# service openvpn start
root@Diabolo:/etc/openvpn# service openvpn status
openvpn.service - OpenVPN service
Loaded: loaded (/lib/systemd/system/openvpn.service; enabled; vendor preset: enabled)
Active: active (exited) since Sat 2016-06-25 19:04:12 CEST; 3s ago
Process: 3956 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 3956 (code=exited, status=0/SUCCESS)
Jun 25 19:04:12 Diabolo systemd[1]: Starting OpenVPN service...
Jun 25 19:04:12 Diabolo systemd[1]: Started OpenVPN service.

output on syslog

Jun 25 19:04:12 Diabolo systemd[1]: Starting OpenVPN service...
Jun 25 19:04:12 Diabolo systemd[1]: Started OpenVPN service.

config file server.conf

port 1194
proto udp
dev tun
ca /etc/openvpn/ca.crt
cert /etc/openvpn/server.crt
key /etc/openvpn/server.key 
dh /etc/openvpn/dh2048.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 208.67.222.222"
push "dhcp-option DNS 208.67.220.220"
keepalive 10 120
comp-lzo
max-clients 100
user nobody
group nogroup
persist-key
persist-tun
status /var/log/openvpn-status.log
log  /var/log/openvpn.log
verb 3
15

The problem is that service config /lib/systemd/system/openvpn.service just calls /bin/true (I have no idea on why it wasn't just removed). Usable configuration might be found in /lib/systemd/system/openvpn@.service, but it still needs to be somewhat hacked.

Solution that worked for me:

1. Create dependency on networking service

To protect it from overwriting, create it in a separate file in subdirectory:

 mkdir -p /lib/systemd/system/openvpn\@.service.d

Create a file in this directory. Its name must end with .conf, for example:

 vi /lib/systemd/system/openvpn\@.service.d/local-after-ifup.conf

Put following content in this file:

[Unit]
Requires=networking.service
After=networking.service

2. Try to start the server

systemctl start openvpn@<CONF_NAME>.service

Where CONF_NAME is the name of your .conf file in /etc/openvpn directory. In your case:

systemctl start openvpn@server.service

3. Enable service autostart if everything works

systemctl enable openvpn@server.service
11

After searching all over I found this link:

https://a20.net/bert/2016/09/27/openvpn-client-connection-not-started-on-ubuntu-16-04/

edit /etc/default/openvpn, uncomment AUTOSTART=”all”
sudo systemctl daemon-reload
sudo service openvpn restart

I boiled it down a bit more into :

echo 'echo "AUTOSTART="\"all"\"" >> /etc/default/openvpn' | sudo -s
sudo systemctl daemon-reload
sudo service openvpn restart
  • 1
    Used to work on my system months ago. No notable change on the system exect I didn't need openvpn for a while. And now it didn't work. This solved the problem... Thanks ! +1 – gissehel Feb 7 '18 at 12:03
1

Due to a bug in /etc/init.d/openvpn ?

# check if automatic startup is disabled by AUTOSTART=none
if test "x$AUTOSTART" = "xnone" -o -z "$AUTOSTART" ; then
  log_warning_msg " Autostart disabled."
  exit 0
fi
if test -z "$AUTOSTART" -o "x$AUTOSTART" = "xall" ; then
  # all VPNs shall be started automatically
  ...

It seems that if AUTOSTART is empty in /etc/default/openvpn then the scripts just exits. So either you choose Phillip's solution or you remove in line 119 the second condition:

-o -z "$AUTOSTART"
  • What “bug”?  The fact that, if you don’t tell it to do anything, it doesn’t do anything?  Are you suggesting that it’s a good idea to modify the system so it starts even if you don’t tell it to?  Are you suggesting that there is something wrong with the answer that says that the user should configure the software so it starts? – G-Man Says 'Reinstate Monica' Oct 29 '18 at 22:24
  • 2
    No, I am just suggesting that like many, I misunderstood the documentation which says: if empty "all" is assumed. Have you seen the number of requests to search engines with "openvpn doesn't start automatically"? – Alex Oct 30 '18 at 8:18
1

Server conf file is myserver.conf

systemctl enable openvpn@myserver
service openvpn@myserver start

Server conf file is yourserver.conf

systemctl enable openvpn@yourserver
service openvpn@yourserver start
-1

As an alternative to Phillip Moxley’s answer, you can edit the /etc/default/openvpn file and change the AUTOSTART line to

AUTOSTART="server"
  • (1) Is this what you meant?  (1a) If yes, please write your answers like this in the future.  They should be self-sufficient — i.e., somebody should be able to read the question and your answer alone, and your answer should make sense.  But, if you’re building on somebody else’s answer, you should say so (referencing it by name and link).  (1b) If this isn’t what you meant, please edit your answer to make it clearer and more complete.  (2) Please don’t include “thanks” in an answer.  (3) How is AUTOSTART="server" different from AUTOSTART="all"?  Is it better?  Why? … (Cont’d) – Scott Apr 3 '18 at 16:49
  • (Cont’d)   …   Again, please do not respond in comments;  edit your answer to make it clearer and more complete. – Scott Apr 3 '18 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.