In this article, we will have explained the necessary steps to install and configure OpenVPN on Ubuntu 18.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.
Virtual private network technology makes possible to access safe, private networks by using less secure networks like the internet. VPNs are typically used to connect physically remote branches of an organization, making them appear as if they were part of the same LAN (for example two offices in different cities). The traffic between the sides of the connection is encrypted using tunnels, which protects the transmitted data and the connection information themselves. For the same characteristics, VPNs are often used to circumvent government restrictions and anonymize internet traffic.
Install OpenVPN on Ubuntu 18.04
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
sudo apt update sudo apt upgrade
Step 2. Installing OpenVPN on Ubuntu.
Now clone the openvpn-install repository using git:
sudo apt install git cd ~ git clone https://github.com/Nyr/openvpn-install.git
Next, change to the directory openvpn-install created by clone and run the installer script:
cd openvpn-install/ openvpn-install.sh chmod +x openvpn-install.sh sudo ./openvpn-install.sh
You will get a couple of prompts to change or confirm default settings for the installation:
Welcome to this OpenVPN "road warrior" installer! I need to ask you a few questions before starting the setup. You can leave the default options and just press enter if you are ok with them. First, provide the IPv4 address of the network interface you want OpenVPN listening to. IP address: 192.168.1.2 Which protocol do you want for OpenVPN connections? 1) UDP (recommended) 2) TCP Protocol [1-2]: 2 What port do you want OpenVPN listening to? Port: 443 Which DNS do you want to use with the VPN? 1) Current system resolvers 2) 188.8.131.52 3) Google 4) OpenDNS 5) Verisign DNS [1-5]: 3 Finally, tell me your name for the client certificate. Please, use one word only, no special characters. Client name: client Okay, that was all I needed. We are ready to set up your OpenVPN server now. Press any key to continue... <Enter>
If the installation was successful, you should get a success message at the end:
sing configuration from ./openssl-easyrsa.cnf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows commonName :ASN.1 12:'client' Certificate is to be certified until Feb 4 07:53:27 2020 GMT (3650 days) Write out database with 1 new entries Data Base Updated Using configuration from ./openssl-easyrsa.cnf An updated CRL has been created. CRL file: /etc/openvpn/easy-rsa/pki/crl.pem 346 Finished! Your client configuration is available at: /root/client.ovpn If you want to add more clients, you simply need to run this script again!
Main OpenVPN server configuration file is, /etc/openvpn/server.conf you are free to tune and tweak it to your liking:
### cat /etc/openvpn/server.conf port 443 proto tcp dev tun sndbuf 0 rcvbuf 0 ca ca.crt cert server.crt key server.key dh dh.pem auth SHA512 tls-auth ta.key 0 topology subnet server 10.8.0.0 255.255.255.0 ifconfig-pool-persist ipp.txt push "redirect-gateway def1 bypass-dhcp" push "dhcp-option DNS 184.108.40.206" push "dhcp-option DNS 220.127.116.11" keepalive 10 120 cipher AES-256-CBC comp-lzo user nobody group nogroup persist-key persist-tun status openvpn-status.log verb 3 crl-verify crl.pem
Step 3. Generate OpenVPN user profile.
We need to generate VPN Profiles to be used by the users. The same script we used for the installation will be used for this:
# ./openvpn-install.sh Looks like OpenVPN is already installed. What do you want to do? 1) Add a new user 2) Revoke an existing user 3) Remove OpenVPN 4) Exit Select an option [1-4]: 1 Tell me a name for the client certificate. Please, use one word only, no special characters. Client name: ramona Generating a 2048 bit RSA private key ...+++ .............................................................................................................................+++ writing new private key to '/etc/openvpn/easy-rsa/pki/private/ramona.key.bmwe46' ----- Using configuration from ./openssl-easyrsa.cnf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows commonName :ASN.1 12:'ramona' Certificate is to be certified until Feb 4 08:10:32 2020 GMT (3650 days) Write out database with 1 new entries Data Base Updated Client ramona added, configuration is available at: /root/ramona.ovpn
From the output you can confirm the location of my profile,/root/ramona.ovpn you need to copy this profile to the user. The location of the associated private key is also provided /etc/openvpn/easy-rsa/pki/private/ramona.key.bmwe46.
Step 4. Connect to OpenVPN Server from the client.
Finally steps, You can use the VPN client of your choice to configure OpenVPN client on your operating system. For those who want to use Official OpenVPN client, go to the downloads page and get the latest release then install it.
That’s all you need to do to install OpenVPN on Ubuntu 18.04. I hope you find this quick tip helpful. If you have questions or suggestions, feel free to leave a comment below.