Start OpenVPN at boot on Ubuntu 18.04

6,488

Solution 1

According to your comment, this line

/lib/systemd/system/[email protected]; 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.

Solution 2

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.

Share:
6,488
Erik
Author by

Erik

Updated on September 18, 2022

Comments

  • Erik
    Erik almost 2 years

    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.

    • Daniele Santi
      Daniele Santi almost 6 years
      Can you share the output of sudo systemctl status openvpn@client and sudo systemctl show openvpn@client ?
    • Erik
      Erik almost 6 years
      sudo systemctl status openvpn@client gives: ● [email protected] - OpenVPN connection to client.ovpn Loaded: loaded (/lib/systemd/system/[email protected]; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:openvpn(8) community.openvpn.net/openvpn/wiki/Openvpn24ManPage community.openvpn.net/openvpn/wiki/HOWTO
    • Erik
      Erik almost 6 years
      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
    Erik almost 6 years
    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/[email protected]‌​vpn.service → /lib/systemd/system/[email protected]. 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?
  • kostix
    kostix almost 6 years
    @Erik, please accept this answer. You should not make the question's title to add " (solved)" to it—that's not how SO works.
  • Theodore Howell
    Theodore Howell almost 5 years
    Thank you! @Erik you should accept