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?

masegaloeh
  • 18,236
  • 10
  • 57
  • 106
waspinator
  • 608
  • 3
  • 13
  • 22

7 Answers7

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.

Zoredache
  • 130,897
  • 41
  • 276
  • 420
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.

masegaloeh
  • 18,236
  • 10
  • 57
  • 106
Ja Sc
  • 101
  • 1
  • 2
9

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

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
dballester
  • 91
  • 1
  • 1
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

elmicha
  • 103
  • 2
waspinator
  • 608
  • 3
  • 13
  • 22
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.

mdpc
  • 11,856
  • 28
  • 53
  • 67
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.

Pedro Brito
  • 202
  • 1
  • 4
0

Note that for 16.04 onward you'll need this:

systemctl start openvpn@server.service
yuranos
  • 101
  • 2