18

I have an *.ovpn file that works if I type in

sudo openvpn client.ovpn

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

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

service openvpn start

How can I do this?

7 Answers 7

20

On Ubuntu any VPN configuration you place in a file named /etc/openvpn/$NAME.conf will be automatically started.

So, all you have to do is copy your client.ovpn to /etc/openvpn/client.conf. I suggest you also use absolute paths in your client.conf for any keys, scripts and so on.

Of course, you might want to double check the /etc/default/openvpn file. By default it will autostart all VPNs, but the AUTOSTART value could have been changed to none, or to be a list of the specific configurations you want automatically started.

1
  • 1
    I tried that. All values were commented out and the documentation stated that the default was all.
    – waspinator
    Dec 17, 2012 at 15:23
10

For Debian OS

  1. Place your configuration file into /etc/openvpn, for example /etc/openvpn/client.conf.

  2. Prefix/comment out lines starting with "down" and "up" (#down and #up) - or delete them (these are calling external script) from client.conf

  3. Reload openvpn configuration

    /etc/init.d/openvpn reload /etc/openvpn/client.conf
    
  4. Check with

    ifconfig
    

    Do you see tun0 interface? Does it have IP assigned? Great.

  5. Remember the IP, reboot and try to connect.

2
9

The client config must have the extension .conf and not .ovpn. Changing client.ovpn to client.conf in /etc/openvpn should work

0
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/

nano /etc/init/myopenvpn

2) Insert into myopenvpn and save:

# OpenVPN autostart on boot upstart job

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

0

You'll have to put this information inside the initialization scripting for openvpn in /etc/init.d. AND aqd appropriate symlinks to the appropriate run level based /etc/rc.d files so that it starts and stops.

0

I did it on a CentOS box with the following command inserted into /etc/rc.local:

openvpn --config /path/to/file.ovpn &

The commands in that file are executed after every multi-user runlevel finishes booting and unlike adding it to a startup script it will not slow down your boot if the VPN takes long to setup, but some people would call this a hack.

2
  • This isn't the Right Way to handle this, especially since Debian already has an initscript which does this.
    – mgorven
    May 24, 2013 at 20:12
  • That's why I added that some people consider this a hack. This is not elegant but does the trick. May 24, 2013 at 20:14
0

Note that for 16.04 onward you'll need this:

systemctl start [email protected]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .