0

I try to start openvpn at boot on a machine running Xubuntu 18.04. I put my credentials of the service I use in a separate file and put the name of that file in the OVPN file as described in: https://askubuntu.com/questions/464264/starting-openvpn-client-automatically-at-boot#464269. When I type: sudo openvpn /etc/openvpn/name.ovpn, openvpn does not ask for my credentials and starts with no errors.

So that is okay. However, I tried every trick as mentioned in the url mentioned earlier but I can not make openvpn build the connection at bootup. Netually I reboot the machine after every change.

Then I tried to add the service to cron with sudo crontab -e. @reboot openvpn /etc/openvpn/name.ovpn The changed crontab is installed. After reboot the machine I am still not protected. ifconfig confirms there is no VPN tunnel set up. According to syslog, openvpn does start without errors. The cron log nor the openvpn log show errors.

I also read many other information on the internet but without any other real solution.

I am at a loss here. Can anyone help?

Thank you in advance.

kostix
  • 1,100
  • 1
  • 7
  • 13
Erik
  • 3
  • 1
  • 4
  • Can you share the output of `sudo systemctl status openvpn@client` and `sudo systemctl show openvpn@client` ? – Daniele Santi Sep 05 '18 at 15:33
  • sudo systemctl status openvpn@client gives: ● openvpn@client.ovpn.service - OpenVPN connection to client.ovpn Loaded: loaded (/lib/systemd/system/openvpn@.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:openvpn(8) https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage https://community.openvpn.net/openvpn/wiki/HOWTO – Erik Sep 05 '18 at 15:38
  • sudo systemctl show openvpn@client gives Type=notify Restart=on-failure PIDFile=/run/openvpn/client.ovpn.pid NotifyAccess=main RestartUSec=5s TimeoutStartUSec=1min 30s TimeoutStopUSec=1min 30s RuntimeMaxUSec=infinity WatchdogUSec=0 WatchdogTimestampMonotonic=0 PermissionsStartOnly=no RootDirectoryStartOnly=no RemainAfterExit=no GuessMainPID=yes MainPID=0 ControlPID=0 FileDescriptorStoreMax=0 NFileDescriptorStore=0 StatusErrno=0 Result=success UID=[not set] GID=[not set] NRestarts=0 – Erik Sep 05 '18 at 15:43

2 Answers2

2

According to your comment, this line

/lib/systemd/system/openvpn@.service; disabled; vendor preset: enabled

seems to indicate that the service is disabled.

You can try to do in sequence

sudo systemctl daemon-reload
sudo systemctl enable openvpn@client

and then reboot.

EDIT as per request

sudo systemctl daemon-reload refreshes the systemd system (re-reads configurations files, regenerates structures, etc.). The manpage says:

daemon-reload
   Reload systemd manager configuration. This will rerun all generators (see systemd.generator(7)), reload
   all unit files, and recreate the entire dependency tree. While the daemon is being reloaded, all sockets
   systemd listens on behalf of user configuration will stay accessible

I personally never understood when it should be used, but often resolved startup problems for me ;)

sudo systemctl enable openvpn@client simply tells the systemd system to enable the specified service, i.e. starting up at the appropriate time and stopping when it should. In the case of openvpn it probably starts after the networking is setup an it stops when shutting down the system.

Daniele Santi
  • 2,479
  • 1
  • 25
  • 22
  • Thank you Mr Shunz, you have solved a problem that I have been working on for some time now. ifconfig and the website of the serviceprovider tell me that the VPN is working now. In response to the second command I got this in my terminal window: Created symlink /etc/systemd/system/multi-user.target.wants/openvpn@client.ovpn.service → /lib/systemd/system/openvpn@.service. In connection to Openvpn I could not find this information anywhere. I have learned I need to read up on systemctl. :-) To complete this tread, could you please explain what these two commands did? – Erik Sep 05 '18 at 16:01
  • 1
    @Erik, please [accept](https://meta.stackexchange.com/a/5235) this answer. You should not make the question's title to add " (solved)" to it—that's not how SO works. – kostix Sep 05 '18 at 16:32
  • Thank you! @Erik you should accept – Theodore Howell Aug 29 '19 at 01:21
1

This answer helped me, I was floundering around simply doing a systemctl enable openvpn, I needed to do systemctl enable openvpn@client The next problem was easily found by looking at journalctl -xe I then found the major problem was the name of my config file. Instead of client.ovpn I changed to client.conf and all worked.

Ian Ward
  • 11
  • 1