Openvpn client autostart linux

OpenVPN AutoStart Ubuntu 18.04

I am trying to set OpenVPN to autostart on boot. With 18.04 Mate I have tried my usual put opvpn config into /etc/openvpn and then edit /etc/default/openvpn to connect all. This does not work, although it worked on 16.04. I have looked into using systemd but I can’t get it to work. I have tried using network manager to connect on log in, as a compromise, this failed due to ethernet not auto connecting if a VPN is set to always be used. So, in summary, what I want is: My openvpn to automatically connect when I boot up. Thanks for all and any help! xm

3 Answers 3

If you save your configuration as a MY_CONNECTION.conf file in your /etc/openvpn directory, you can do the following:

systemctl enable openvpn@MY_CONNECTION systemctl start openvpn@MY_CONNECTION 

where MY_CONNECTION is the same from MY_CONNECTION.conf .

So if you have multiple connections, you would have multiple systemctl calls.

systemctl enable openvpn@MY_CONNECTION1 systemctl start openvpn@MY_CONNECTION1 systemctl enable openvpn@MY_CONNECTION2 systemctl start openvpn@MY_CONNECTION2 

Hi Matt. Thank you for your answer. systemctl enable openvpn@MY_CONNECTION systemctl start openvpn@MY_CONNECTION This works if I do it manually. It does not work on boot. My VPN does not automatically connect, for some reason.

I think, perhaps, the issue is, when this command is called it request a password via a GUI dialogue box.

So the line in /etc/default/openvpn that reads «WARNING: If you’re running systemd the rest of the options in this file are ignored.» should say «. all of this file is ignored» as clearly AUTOSTART is ignored if favour of this method.

Below you find the steps I did to configure my Private Internet Access (PIA) OpenVPN tunnel. I use Switzerland.ovpn to refer to OpenVPN configuration. Please substitute this with the filename appropriate for your configuration.

I used Ubuntu 18.04, but it should work on any Linux distro using systemd. I only don’t know if the network-manager will override this or not.

Dependencies

OpenVPN Configuration

  1. sudo mkdir /etc/openvpn/PIA (change PIA to the name of your choice)
  2. Download your OpenVPN config files, for example:
sudo wget https://www.privateinternetaccess.com/openvpn/openvpn.zip https://www.privateinternetaccess.com/openvpn/openvpn-strong.zip 

Skip steps 7 to 10 if you do not use a password

  1. (optional) sudo touch piapass.txt
  2. (optional) sudo chmod 700 piapass.txt
  3. (optional) Type sudo nano piapass.txt and put the following content (changing username and password to the values appropriate for your configuration)

Systemd Startup Service Setup

Change piavpn.service for whatever name you would like your startup OpenVPN connection service to have.

  1. cd /etc/systemd/system/
  2. sudo touch piavpn.service
  3. sudo chmod 644 piavpn.service
  4. Type sudo nano piavpn.service and put the following content (make sure to adapt the line starting with ExecStart to match your configuration):
[Unit] Description=Private Internet Access VPN (Swiss) After=multi-user.target [Service] Type=idle ExecStart=/usr/sbin/openvpn --config /etc/openvpn/PIA/Switzerland.ovpn [Install] WantedBy=multi-user.target 

After the reboot your OpenVPN connection should be set up automatically on boot.

Источник

Guide: Configure OpenVPN autostart Linux connection

Configure Openvpn Autostart Linux Image

Your system should be safe from the moment it boots up. In order to achieve this, your VPN connection should start automatically as soon as you boot your system. This guide tells you how to configure OpenVPN autostart Linux option, in order for your Linux system to be always safe and protected from prying eyes. To start, you should have installed OpenVPN and have it up and running. One of the perks of an auto start VPN setup is that you do it once and forget about it. Say you want to access same content in the same country, and don’t want to activate the script manually every time. The good news is that this guide will teach you how to do just that. [Read: VPN vs DNS: Which one should you choose and why?]

Configure Openvpn Autostart Linux Image

Configure OpenVPN autostart Linux: Requirements

  • A Debian distribution. For this tutorial, I will be using OSMC. You can compare it with other distros, for example compare OSMC vs OpenELEC, and choose the one that fits best your needs.
  • An installation of OpenVPN for your system.
  • A VPN provider.

Surfshark VPN Exclusive Offer — 82% off ($2.39/month):
♦ Hide your browsing (no logs), Anonymize Streaming and Downloads
♦ Wireguard Protocol support for VPN.
♦ Circumvent Geo/Country Restrictions and access worldwide content
♦ Works on Windows, Mac, Linux, Android, iOS, Router, and more
♦ 1 TB Encrypted Storage
♦ Money back guarantee — Sign Up Now

Configure Linux OpenVPN Autostart

For this tutorial, I will be writing yourVpnServer instead of the actual VPN server. You will have to fill in the required information. Depending on your provider the name of the server will differ. The name of the server is the one given by the filename on the .ovpn file you can get from your VPN provider. An example could be: uk2.nordvpn.com.tcp443.ovpn .

First we will need to login to the VPN server. Select your favorite VPN server, then type in terminal the following command:

sudo nano "yourVpnServer.ovpn”

Change the line that says:

After you do this, press Ctrl+X and then Y in order to save your changes.

Autostart Openvpn Linux Tutorial

After you do this, create a file with nano. You will not be able to see this file if you run a ls command. Type in terminal:

On this file, type your username and password for your VPN provider, one below the other, as shown in the picture. Then press Ctrl+X and Y in order to save your changes.

Openvpn Start On Boot Linux

To test that your connection is working properly, type:

sudo openvpn yourVpnServer.ovpn

This command will start your VPN connection. If you want to stop and kill the VPN tunnel, use Ctrl+C .

Linux OpenVPN Autostart script: configuring automatic connection

You need to have root user privileges in order for these instructions to work. Type the following instructions:

sudo su openvpn yourVpnServer.ovpn

Stay logged in as root and continue. In my case I’m using NordVPN as provider so I called the file NordVPN, but you can call it whatever you like. After you type the instructions above, type the following command:

nano /etc/init.d/youVpnProvider

You have started creating a script to automatically connect to your VPN provider. Copy and paste the script below in order to get the right commands to achieve this. Please note that the line where it says yourVpnServer.ovpn should contain the .ovpn filename for the server you will be using instead. You will also need the full path to the .ovpn file you will use, which for this example is /etc/openvpn .

#!/bin/sh ### BEGIN INIT INFO # Provides: OpenVPN # Required-Start: # Required-Stop: # Should-Start: # Should-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start and stop OpenVPN # Description: OpenVPN ### END INIT INFO path_to_ovpn_files="/etc/openvpn" ovpn_file_to_use="yourVpnProvider.ovpn" # Do NOT change anything below this line unless you know what you are doing! exec 1>/var/log/yourVpnProvider.service.log 2>&1 case "$1" in start) echo "Connecting to OpenVPN " cd "$path_to_ovpn_files" /usr/sbin/openvpn --config "$ovpn_file_to_use" & ;; stop) echo "Closing connection to OpenVPN " killall openvpn ;; *) echo "Usage: /etc/init.d/vpn " exit 1 ;; esac exit 0

Openvpn Start On Boot Linux

Enabling the Linux OpenVPN autostart service

Type the following commands on your terminal:

update-rc.d yourVpnProvider defaults service --status-all |grep yourVpnProvider

The console should display: [ — ] yourVpnProvider.service

Type these commands on your terminal:

service yourVpnProvider start service yourVpnProvider stop

They should execute without problem. Also, you can check the logs of your service with this command:

cat /var/log/yourVpnProvider.service.log

This will let you determine if the tunnel is being established correctly or not. After you have tested these things, it’s time to see the external IP address of your device. You could use this excellent tutorial on Commandline IP Address Lookup on Linux, or execute the following command for a less elaborate response:

Reboot the device to make sure that the Linux OpenVPN Autostart feature is working correctly. That’s it! You have finished the tutorial to successfully configure OpenVPN autostart Linux connection! Do you still need advice with VPN usage? If you use a Windows system, perhaps it’s better if you use our tutorial on how to configure OpenVPN autoconnect on Windows 10. You can also use providers such as IPVanish and make things a bit easier. Install IPVanish OpenVPN on Linux Mint 18 or simply Install IPVanish on Ubuntu to secure your browsing on these platforms. Access geoblocked content and secure your browsing, today!

Источник

Auto start Openvpn with one .ovpn file

Hi i bought vpn access form a vpn provider, i got a bunch of .ovpn files. How can i get openvpn to startup one of these .opvn files under start/boot up? I would like to, not have to run openvpn —config VPNservername.ovpn every time i have to do a reboot. I’m running ubuntu 12.04 server. I have installed openvpn

5 Answers 5

When you have installed openvpn from the repo, everything is already prepared for you.

Place the whatever.conf file in /etc/openvpn/ and a daemon will be started for it at boot.

Please note that *.opvn will not work, *.conf will.

@staR I don’t know if that was really necessary. But anyway, please try to copy whatever.ovpn to /etc/openvpn/ . You’ll have to have root rights for this and rename it to whatever.conf . Good luck!

Note, that /etc/default/openvpn file contain AUTOSTART option. You can add there all your configs without .conf at the end you want to autostart. But don’t forget to do:

This is irrelevant to this question as it was asked a long time ago and the OP is running Ubuntu 12.04. And it dosen’t seem the OP is going to accept — he hasn’t been on for 3 months.

@ubashu I don’t think this is irrelevant. Answers should change based on newer versions of software. This is the top result for me when I search.

If on ubuntu server: go to rc.local. vi /etc/rc.local add the following line openvpn —config /your/path/file.ovpn save and reboot.

Put the keys, certificates, and client configuration file in the proper folders.

/etc/openvpn/ca.crt /etc/openvpn/client/client0.crt /etc/openvpn/client/client0.key /etc/openvpn/client/ta.key /etc/openvpn/client/client0.conf 

Enable OpenVPN client service to start at boot and start it.

systemctl enable openvpn-client@client0 systemctl start openvpn-client@client0 

NOTE: In the example «client0» is the name of the configuration chosen!

TIP: Client configuration example.

client remote 1194 dev tun proto udp resolv-retry infinite nobind persist-key persist-tun verb 3 cipher AES-256-CBC keepalive 10 120 compress lz4-v2 auth-nocache remote-cert-tls server ca /etc/openvpn/ca.crt cert /etc/openvpn/client/client0.crt key /etc/openvpn/client/client0.key tls-auth /etc/openvpn/client/ta.key 1 

Источник

Читайте также:  Узнать серийный номер флешки линукс
Оцените статью
Adblock
detector