Skip to content

Set Up OpenVPN on a Linux Server – Create Your Secure VPN Infrastructure

Discover how to secure your internet connection and access blocked content with OpenVPN on Linux servers → Learn more now

12 November 20262 min read47 Views0 helpful

Introduction

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.

Preparation

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.

Code
nano /usr/sbin/tunscript.sh 

Then insert the following lines:

Code
#!/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:

Code
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:

Code
@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.

Installation

To install OpenVPN, run the following command in the console:

Code
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:

Code
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.

Configuration

Adding More Clients

If you need multiple connections, it makes sense to create multiple accounts. To create another account, run this command:

Code
wget https://git.io/vpn -O openvpn-install.sh && bash openvpn-install.sh

Choose 1 and confirm. Then enter the client name.

Removing Clients

To delete a client, run the following command:

Code
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.

Uninstallation

If you no longer need OpenVPN, you can uninstall it like this:

Code
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.

Connecting to the VPN

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.”

Info

If you have imported multiple files, you must select the client you want to use and then click Connect.

FAQ

Frequently asked questions

On root servers, you first need to enable the TUN network driver (script in /usr/sbin, run via cron job at reboot). Then install the OpenVPN service using your distribution's package manager.
No, this step is not necessary on root servers.
OpenVPN enables a secure, encrypted connection between your device and a VPN server to protect your internet connection, safeguard your online privacy, and access geo-restricted content worldwide.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 Users found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.