How to Install OpenVPN on Ubuntu 22.04

How to Install OpenVPN on Ubuntu 22.04

You can extend a private network across public networks by using a virtual private network, or VPN. It improves your online security because there is a great likelihood that your data may be compromised if, for instance, you use a hotel’s internet connection for business while you are there. Unauthenticated access to your connection is prevented by the confidentiality and encryption of VPN connections. We will walk through each step needed to set up OpenVPN Server on Ubuntu 22.04 today in this guide.

OpenVPN

In order to access remote websites, establish secure connections, and improve security through the use of encryption, authentication, and of course certification using the OpenSSL library, one can utilize the open-source program OpenVPN. Currently, we’ll configure OpenVPN on Ubuntu 22.04.

Update the System Packages

sudo apt-get update && sudo apt-get upgrade

Additionally, your system’s packages will be immediately updated.

Install openVPN

sudo apt -y install openvpn

You must now wait for a while before creating a static key.

Launch the VPN Server and Create a Static Key for VPN Tunnel Encryption.

openvpn --genkey --secret static-OpenVPN.key
sudo openvpn --dev tun --ifconfig 172.16.0.1 172.16.0.2 --cipher AES-256-CBC --secret static-OpenVPN.key &

The “&” at the end of the command above, which you may have noticed, allows you to run OpenVPN in the background without having to keep the terminal window open.

Check to See if Your Path Is True

Simply use the following command to get tun0 with 192.168.45.1 as its IP address.

ip a show tun0

Now we must use the following command to see if the UDP port 1194 is available for connections.

netstat -anu | grep 1194

And this would result in something like this.

1..How to Setup OpenVPN Server on Ubuntu 22.04 2

Configure Firewall

The firewall can be configured with the following command.

$ sudo ufw allow from any to any port 1194 proto udp

And you’ll see the output shown below.

2..How to Setup OpenVPN Server on Ubuntu 22.04 3

Now that it can accept incoming connections, the OpenVPN server is operational.

How will a remote client connect to the OpenVPN server at this point? You must perform the subsequent actions.

Install OpenVPN

sudo apt -y install openvpn

From the OpenVPN server, send the static-OpenVPN key file to the client.

First, we must transmit the file securely from the server to the client; however we will employ the SCP command as seen below.

scp badshah@opensourcelisting:/home/ubuntuser/static-OpenVPN.key

Use your username when issuing this command from the client side.

Creating a VPN Connection to the Server

We may create a VPN tunnel to the server using the following command, however you must modify the IP address to match the server you are connecting to.

$ sudo openvpn --remote YOUR-OPENVPN-SERVER-IP-OR-HOST --dev tun --ifconfig 192.168.45.1 192.168.45.2 --cipher AES-256-CBC --secret static-OpenVPN.key &

Did you notice the AES-256-CBC cypher? So, that is the safest method of encrypting and decrypting the data string.

Verifying the connection’s success

If the connection was successful and you have completed step 3, you should receive the following message.

3..How to Setup OpenVPN Server on Ubuntu 22.04 4

Using the following command, we will now ping a host on the remote server to verify the connection’s success.

ping -c 1 192.168.45.1

Install OpenVPN on Ubuntu 20.04

Conclusions

In this article, we went over every step needed to set up OpenVPN to accept incoming connections. We also learnt how to use Ubuntu to remotely connect to an OpenVPN server. Please get in touch with us if you encounter any errors or problems, as we are always delighted to assist our neighborhood.

Follow us TwitterFacebookLinkedIn

Open Source Listing

Previous Post
Next Post

Comments

Avatar for Log in
Log in

Cool. I spent a long time looking for relevant content and found that your article gave me new ideas, which is very helpful for my research. I think my thesis can be completed more smoothly. Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *