How to autostart OpenVPN (client) on Ubuntu 12.04 CLI?

3

I have an *.ovpn file that works if I type in: sudo openvpn filename.ovpn.

Now I would like to start up OpenVPN when I boot the computer. It's a headless version of Ubuntu 12.04 64-bit if that matters.

I copied filename.ovpn to /etc/openvpn, but it's not starting, even if I run: service openvpn start.

How can I do this?

waspinator

Posted 2012-12-17T03:43:03.467

Reputation: 151

see: http://upstart.ubuntu.com/getting-started.html

– mbx – 2012-12-17T08:12:42.353

Have you tried naming your file client.conf? – user2313067 – 2014-02-18T08:52:22.937

Answers

1

  1. Ubuntu is derived from Debian. Debian has a manual page about this: https://wiki.debian.org/OpenVPN#Auto-start

  2. They both have a README file installed with the openvpn package. That file says, how and where to place configs for autostart to work, but it has instructions for old init system and is misleading for systems with systemd.

Configs should be put into /etc/openvpn/filename.conf, not .ovpn.

On the new systems please make use of systemd cloned service. To enable (autostart) service with configuration /etc/openvpn/filename.conf do:

systemctl enable openvpn@filename.service

Then you work with newly created service as usual.

On the old Debian (pre-systemd) by default "openvpn" service tries to run them all. /etc/default/openvpn could be used to select which configurations to execute by default.

This applies equally to all "peer-to-peer", "client" and "server" openvpn deployment variants.

Nikita Kipriyanov

Posted 2012-12-17T03:43:03.467

Reputation: 505

1

It would be nice to have a un hacker way of doing it, but this will have to do for now.

1) Create file myopenvpn in /etc/init.d/

nano /etc/init.d/myopenvpn

2) Insert into myopenvpn and save:

# OpenVPN autostart on boot script

start on runlevel [2345]
stop on runlevel [!2345]

respawn

exec /usr/sbin/openvpn --status /var/run/openvpn.client.status 10 --cd /etc/openvpn --config /etc/openvpn/client.conf --syslog openvpn

SOURCE: http://www.hackerway.ch/2012/12/11/how-to-auto-start-openvpn-client-in-debian-6-and-ubuntu-12-04/#comment-79

waspinator

Posted 2012-12-17T03:43:03.467

Reputation: 151