OpenVPN is a powerful and versatile VPN software that enables a secure connection over the internet. It is an open-source solution offering robust and configurable VPN technology to establish an encrypted connection between your device and a VPN server. With OpenVPN, you can secure your internet connection, protect your online privacy, and access geo-restricted content worldwide regardless of your location. This guide shows you how to install and configure the OpenVPN service on a Linux server.
First, the network driver TUN must be enabled. This step is not necessary on root servers.
To do this, create a new file named tunscript.sh in the /usr/sbin directory.
nano /usr/sbin/tunscript.sh
Then insert the following lines:
#!/bin/bash
mkdir /dev/net
mknod /dev/net/tun c 10 200
chmod 0666 /dev/net/tun
Save the file with CTRL+O, confirm with Y, and press Enter. To exit, press CTRL+X. Then run the following command:
chmod +x /usr/sbin/tunscript.sh
Next, open the cron editor with crontab -e and select the nano editor. Add this line at the end of the file:
@reboot /usr/sbin/tunscript.sh || exit 1
Save again with CTRL+O, confirm with Y, and press Enter. Exit with CTRL+X. After a reboot, the script should run automatically.
To install OpenVPN, run the following command in the console:
wget https://git.io/vpn -O openvpn-install.sh && bash openvpn-install.sh
A dialog will appear asking if you want to use UDP or TCP. We recommend UDP, so enter 1 and confirm with Enter. Next, you will be asked for a port for OpenVPN – we recommend using the default port.
Then you need to configure the DNS server. We recommend Google Public DNS or Cloudflare DNS:
8.8.8.8 / 8.8.4.4 - Google Public DNS
1.1.1.1 / 1.0.0.1 - Cloudflare DNS
In the next step, enter a client name. You can choose any name you like, for example, your device’s name.
If you need multiple connections, it makes sense to create multiple accounts. To create another account, run this command:
wget https://git.io/vpn -O openvpn-install.sh && bash openvpn-install.sh
Choose 1 and confirm. Then enter the client name.
To delete a client, run the following command:
wget https://git.io/vpn -O openvpn-install.sh && bash openvpn-install.sh
Select the number of the client from your list that you want to remove and confirm with Enter. You will be asked to confirm the deletion. If you are sure, press Y and then Enter. The client will then be removed.
If you no longer need OpenVPN, you can uninstall it like this:
wget https://git.io/vpn -O openvpn-install.sh && bash openvpn-install.sh
Press 3 and confirm. Confirm once more and OpenVPN will be uninstalled.
To connect to your VPN, we recommend the OpenVPN Client. Simply download it on the device you want to connect from.
Connect to your server via SFTP to download the created .ovpn file and then delete the file from the server. After installing the client, start the program. Right-click the OpenVPN icon in the taskbar. Then click “Import file” and select the previously downloaded file, click “Open.” To connect, click the icon again and select “Connect.”
If you have imported multiple files, you must select the client you want to use and then click Connect.