Installing and Configuring OpenVPN on Ubuntu 22.04/20.04

Posted on the 14 April 2023 by Top10

OpenVPN is a fast, popular open source VPN (virtual private network) software. It uses TCP and UDP data transfer protocols, and the VPN tunnels are secured by the OpenVPN protocol with SSL/TLS authentication, certificates, credentials and optional MAC address blocking, as well as multi-factor authentication.

OpenVPN can be used on a wide variety of devices and systems. Like most VPN protocols, it has a client-server architecture. The OpenVPN Access Server runs on a Linux system, while clients can be installed on other Linux, Windows, and macOS systems, as well as mobile operating systems such as Android, Windows Mobile, and iOS.

The OpenVPN access server accepts incoming VPN connections, and OpenVPN Connect clients or any OpenVPN-compliant open source clients can initiate a connection to the server.

In this article, you will learn how to set up an OpenVPN access server on Ubuntu 22.04/Ubuntu 20.04 and connect VPN clients from other Linux systems.

Step 1Setting Up an OpenVPN Server on Ubuntu

1. Installing and configuring an OpenVPN server manually is not an easy task, as experience shows. For this reason, we will be using a script that will allow you to set up your own secure OpenVPN server in seconds.

Before you download and run the script, please note that the script will automatically detect your server's private IP, but you need to pay attention to your server's public IP, especially if it's behind NAT.

To find out the public IP address of your server, run the following wget or dig command.

$ wget -qO - icanhazip.com
OR
$ dig +short myip.opendns.com @resolver1.opendns.com

2. Now download the installer script using the curl command line tool and then make it executable using the chmod command as follows.

$ curl -O 
$ chmod +x openvpn-install.sh

3. Then run the installer executable script as shown below.

$ sudo bash openvpn-install.sh

The first time you run the script, it will ask you a few questions, read them carefully and give answers according to your preferences in order to set up your OpenVPN server.

4. After the VPN installation process is completed, the client configuration file will be written in the current working directory. You will use this file to configure the OpenVPN client as described in the next section.

5. Next, make sure the OpenVPN service is running by checking its status with the following systemctl command.

$ sudo systemctl status openvpn

6. Also confirm that the OpenVPN daemon is listening on the port you told the script to use using the ss command, as shown in the figure.

$ sudo ss -tupln | grep openvpn

7. If you check your network interfaces, a new interface has been created for the VPN tunnel, you can confirm this with the IP command.

$ ip add

Step 2Setting Up OpenVPN Clients on Ubuntu

8. Now it's time to set up your OpenVPN client and connect it to the VPN server. First, install the OpenVPN package on the client machine as follows.

$ sudo yum install openvpn    #RHEL-based Systems
$ sudo apt install openvpn    #Debian-based Systems
$ sudo dnf install openvpn    #Fedora Linux

9. On a desktop system, the network-manager-openvpn package must also be installed in order to perform VPN settings from the GUI.

$ sudo yum install network-manager-openvpn     #RHEL-based Systems
$ sudo apt install network-manager-openvpn     #Debian-based Systems
$ sudo dnf install network-manager-openvpn     #Fedora Linux

10. After installing the above packages, start the OpenVPN service, for now enable it to start automatically on system boot and check its status to make sure it is running.

$ sudo systemctl start openvpn 
$ sudo systemctl enable openvpn 
$ sudo systemctl status openvpn

11. Now you need to import the OpenVPN client settings from the OpenVPN server. Open a terminal window and use the SCP command to capture the file as shown.

$ cd ~
$ scp [email protected]:/home/tecmint/tecmint.ovpn .

12. Open System Preferences, then go to the Networks section. In the VPN section, click the add button to get the options you need.

13. In the pop-up window, select "Import from file" as shown in the following screenshot. Then go to the file manager and select the .ovpn client configuration file you downloaded from the server.

14. On other Linux desktops, click the network icon in the system tray, go to the Network Connections section. Then click the plus button to add a new connection. From the dropdown list, select "Import Saved VPN Configuration..." as shown in the following screenshot.

Create a connection and import the file.

15. After importing the file, you need to add the VPN settings as shown in the following screenshot. Then click the Add button.

16. Your VPN client settings should be added successfully. You can connect to the OpenVPN server by enabling the VPN as shown in the following screenshot.

17. The VPN connection should now be established successfully as shown in the following screenshot.

18. If you check the network interface connections using the IP add command, a VPN tunnel interface should now exist, as shown in the following screenshot.

$ ip add

Step 3Setting Up an OpenVPN Client on Linux

19. To connect another Linux server as a VPN client, make sure you have installed the OpenVPN package and started and enabled the OpenVPN service as described above.

Then download the .ovpn client file and copy it to the /etc/openvpn/ directory as shown in the figure.

$ scp [email protected]:/home/tecmint/tecmint.ovpn .
$ ls
$ sudo cp tecmint.ovpn /etc/openvpn/client.conf

20. Next, start the VPN Client service, enable it, and check its status with the following commands.

$ sudo systemctl start [email protected]
$ sudo systemctl enable [email protected]
$ sudo systemctl status [email protected]

21. Then confirm that the VPN tunnel interface has been created using the IP add command as shown in the figure.

$ ip add

22. To configure other OpenVPN clients on operating systems, use the following clients:

Step 4Removing OpenVPN from Ubuntu

23. If you want to add a new VN user, revoke an existing user, or remove the OpenVPN server from your system, simply run the installer script again. Then select what you want to do from the list of options and follow the prompts.

$ sudo bash openvpn-install.sh

This concludes this guide. For more information go to the repository openvpn-install script Github.

2737400cookie-checkOpenVPN installation and setup in Ubuntu 22.04/20.04no

Similar

Инструкции,Программы,linux,OpenVPN,ubuntu,Ubuntu 20.04,Ubuntu 22.04,VPN
#Installing #configuring #OpenVPN #Ubuntu #22.0420.04