How to Set Up and Configure OpenVPN Server and Client on Ubuntu 20.04 LTS.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

So, in this guide you will learn how to Set Up and Configure OpenVPN Server and Client on Ubuntu 20.04 LTS.

Open source OpenVPN uses VPN technologies to secure and encrypt data sent over the internet. Its custom VPN protocol uses SSL/TLS for key exchange and released under the GNU GPL license.

OpenVPN is extremely popular and a full-featured SSL VPN (Virtual Private Network) software. It implements OSI layer 2 or 3 secure network extension using the SSL/TLS protocol.

This tutorial provides step-by-step instructions for configuring an OpenVPN Server and OpenVPN Client on Ubuntu 20.04 LTS Linux server.

Step 1 – Update your system:

First you have to install Ubuntu 20.04 update by executing following commands:

# apt update

# apt upgrade

Step 2 – Find and note down your IP address:

Use the ip command as shown below.

# ip a

# ip a show eht0

We can try the following dig command/host command to find out your public IP address from Linux command line:

# dig +short myip.opendns.com @resolver1.opendns.com

# dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2 }'

Step 3 – Configure OpenVPN Server and Client on Ubuntu 20.04 LTS

Use wget command in order to download the openvpn-install.sh script.

wget https://git.io/vpn -O openvpn-ubuntu-install.sh

Note: If you want password authentication along with certificates? Try the following:

wget https://raw.githubusercontent.com/angristan/openvpn-install/master/openvpn-install.sh -O openvpn-ubuntu-install.sh

Make sure you set up permissions using the chmod command:

# chmod +x openvpn-ubuntu-install.sh

Execute the openvpn-install.sh script to install the OpenVPN server on Ubuntu machine:

It will ask you series of questions and you have to select options as per your requirements. Please see the screenshot below.

# ./openvpn-ubuntu-install.sh

Desktop or Mobile client configuration:

When VPN server configuration done, we can create a desktop client VPN configuration file. You will be prompted for a client name and then client configuration will be available on OpenVPN Server.

start/stop/restart OpenVPN server on Ubuntu server:

# systemctl status [email protected]

# systemctl start [email protected]

# systemctl stop [email protected]

# systemctl restop [email protected]

Step 4 – Connect an OpenVPN server using Ubuntu Client:

On your VPN server you will see a client configuration file called DesktopVPNClient.ovpn.

You will have to copy this file to your linux client machine using the scp command.

Install openvpn client on your ubuntu client machine.

# apt install openvpn

You can view the DesktopVPNClient.ovpn file in linux editor like vi or vim etc.

# vi DesktopVPNClient.ovpn

Now, copy the DeskptoVPNClient.ovpn in /etc/openvpn/client.conf

# cp DesktopVPNClient.ovpn  /etc/openvpn/client.conf

You can test the connectivity from the CLI.

# openvpn --client --config /etc/openvpn/client.conf

Our Linux client will automatically connect when computer restart using openvpn script/service:

# systemctl start openvpn@client

Step 5 – Verify connectivity between VPN Server and VPN Client.

Execute the following commands after connecting to OpenVPN server to your Linux client:

On VPN Client machine:

Check the interface detail on VPN Server machine.

# ip a

You will see tun0 interface with 10.8.0.2 IP address.

Ping to the VPN server gateway.

# ping 10.8.0.1

If all goes well you will be able to see the ping reply and which means VPN server and VPN client connected successfully.

On VPN Server machine:

Check the interface detail on VPN Server machine.

# ip a

Make sure routing setup working.

#ip route

Step 6 – Add or remove OpenVPN client.

Log in to your Ubuntu Linux server and run the script again

# ./openvpn-ubuntu-install.sh

You will see different options for add, revoke, remove or exit, chose options as per your need.

Select an option:

   1) Add a new client

   2) Revoke an existing client

   3) Remove OpenVPN

   4) Exit

Option:

Choose option # 1 to add a new VPN client/user and option # 2 to remove the existing VPN client and user. Let us add a new client/user called iphone:

Conclusion:

Congratulations!! You successfully set up an OpenVPN server and OpenVPN client on Ubuntu 20.04 machine. For more detail please refer to the openvpn site.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Sajid Ali
Sajid Ali
Linux & Windows Server Administrator | Cloud Architect: I possess 10 years of professional experience with administration of different hosting provider’s Linux and Windows based servers on a large production level.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook