OpenVpn is currently the most popular protocol used as a VPN, and any VPN provider you check will definitely have this service on their list of protools. Even some providers are content with just this protocol and only offer OpenVPN. Join us in this article to teach you How to Setup an OpenVPN Server on Ubuntu 22.04. You can check out the packages offered on the Eldernode website if you would like to purchase an Ubuntu VPS server.
Table of Contents
Tutorial Install OpenVPN Server on Ubuntu 22.04
Introduction to OpenVPN
OpenVPN is a commercial open-source software that allows you to implement a VPN point-to-point or site-to-site. OpenVPN is one of the most secure filtering protocols and can not be blocked due to its open-source feature and has a high degree of flexibility. The OpenVPN protocol can setup its own encryption tunnel based on the TCP protocol for maximum reliability or the UDP to increase speed.
In the continuation of this article, after mentioning some of the benefits of OpenVPN, we will teach you step by step how to set up an OpenVPN server on Ubuntu 22.04.
OpenVPN Advantages
-> Very safe
-> Hard to block
-> Full control of connections
-> Full support for leading privacy
-> Data protection against profiteers
-> Compatibility with multiple operating system
Setup an OpenVPN server on Ubuntu 22.04
Setting up OpenVPN through a manual process can be challenging for new users who do not have experience working with Linux and VPNs. This guide shows an easy way to install OpenVPN server on Ubuntu 22.04. This is a scripted method so anyone with a basic knowledge of Linux can follow it:
In first step, type the following command in command-line terminal and start installation:
sudo apt update
sudo apt install openvpn
Then create a static key to use for VPN tunnel encryption:
openvpn --genkey --secret static-OpenVPN.key
Now setup an OpenVPN server to receive incoming connection requests:
sudo openvpn --dev tun --ifconfig your_ip_address_1 your_ip_address_2 --cipher AES-256-CBC --secret static-OpenVPN.key &
Note that in the above command, instead of your_ip_address_1 and your_ip_address_2, type the IP addresses you want. By performing the above command, you do not need to keep a terminal open to run this service.
Now your system has a new network interface called tun0 with your IP address. Type following command to confirm:
ip a show tun0
Then check that the UDP port 1194 on your system is open, to ensure that the VPN server is working properly:
netstat -anu | grep 1194
Finally enter following command to configure Ubuntu’s UFW firewall to allow incoming connections on UDP 1194 port:
sudo ufw allow from any to any port 1194 proto udp
How to Connect to the OpenVPN Server Using the OpenVPN Client
Now follow the steps in this section to connect to the OpenVPN server using the OpenVPN client.
Open the terminal and type the following command to start installing OpenVPN server:
sudo apt install openvpn
In next step, your client device needs an OpenVPN server to connect to the static-OpenVPN.key encryption key file. Use the following command to transfer a file using scp:
scp Evelyn@eldernode:/home/Evelyn/static-OpenVPN.key .
Now use this command to create a VPN tunnel to the server, but replace the YOUR-OPENVPN-SERVER-IP-OR-HOST string with the IP address or host name of the VPN server to which you are connected:
sudo openvpn --remote YOUR-OPENVPN-SERVER-IP-OR-HOST --dev tun --ifconfig your_ip_address_1 your_ip_address_2 --cipher AES-256-CBC --secret static-OpenVPN.key &
After creating the VPN tunnel, you will see the following message:
Initialization Sequence Completed
Finally ping a host on a remote network to connect to the VPN server:
ping -c 1 your_ip_address
Conclusion
In this article, we learned how to setup an OpenVPN server on Ubuntu 22.04 using a scripted method, that anyone with basic knowledge of Linux can follow it. This way you can establish a secure VPN connection between the server and the client machine.