Secure Your Network: How to Set Up OpenVPN on Linux (CentOS/Ubuntu/Debian/Amazon)

Secure Your Network: How to Set Up OpenVPN on Linux (CentOS/Ubuntu/Debian/Amazon)


This guide explains how to install OpenVPN, an open-source Virtual Private Network (VPN) solution, on a Linux server. OpenVPN allows you to create a secure private network using the public internet, providing enhanced privacy, remote access, and secure connections for IoT devices or cloud networks.

Why Choose OpenVPN?

OpenVPN offers numerous advantages, such as:

  • Economical, secure private networking via the public internet.
  • Remote access to internal services for enhanced productivity.
  • Reduced risk of unauthorized access to sensitive resources.
  • Encryption to safeguard data on public or untrusted networks.
  • Centralized threat management for remote networks.

With this guide, you’ll set up a VPN server in minutes using a simple script for various Linux distributions, including Debian, Ubuntu, CentOS, Fedora, and Arch Linux.

System Requirements

  • A VPS server with at least 512 MB RAM.
  • Virtualization types: KVM, Hyper-V, or VMware recommended.
  • Internet speed: 100 Mbps or higher.

Step-by-Step Installation Guide

Step 1: Download the OpenVPN Installation Script

1. Create a directory for the installation files:

mkdir /root/vpn
cd /root/vpn

2. Download the script using curl:

curl -O https://raw.githubusercontent.com/angristan/openvpn-install/master/openvpn-install.sh

3. Make the script executable:

chmod 755 openvpn-install.sh

Step 2: Run the Installer

1. Execute the script:

./openvpn-install.sh

2. Follow the on-screen prompts:

  • Server IP Address: Input your public IPv4 address (or press Enter to accept the default).
  • IPv6 Support: Enable by typing y (if available).
  • Port Selection: Choose a port:
    • Default (1194)
    • Custom
    • Random (49152–65535, recommended for enhanced security).
  • Protocol: Select UDP (Option 1) for better speed.
  • DNS Provider: Choose an option (e.g., Google DNS by typing 9).
  • Compression: Decline by selecting n (to avoid security risks).
  • Encryption Customization: Use the default settings by typing n.

3. Proceed with the setup and provide a client name when prompted:

Client name: yourclientname

4. For authentication, choose a passwordless client (Option 1) for better auto-reconnect functionality.

Once the installation is complete, the script generates a .ovpn configuration file (e.g., yourclientname.ovpn) in the /root/vpn directory. Download this file to your computer to connect using the OpenVPN client.

Step 3: Configure the Firewall

Add the OpenVPN port to your firewall rules to allow traffic:

  • Allow UDP or TCP traffic based on your chosen protocol during installation.

Step 4: Managing OpenVPN

To manage OpenVPN, navigate back to the installation directory and rerun the script:

cd /root/vpn
./openvpn-install.sh

You will be presented with options:

  1. Add a new user.
  2. Revoke an existing user.
  3. Remove OpenVPN.
  4. Exit.

Connecting to Your VPN

  1. Download and install the OpenVPN Connect client on your device.
  2. Import the .ovpn file generated during the installation.
  3. Connect to your VPN to enjoy secure and private browsing.

OpenVPN and Linux: A Perfect Match for Secure Browsing

Setting up an OpenVPN server on a Linux system is a straightforward process using the provided script. This guide walks you through downloading, configuring, and managing your VPN server, offering robust security and privacy benefits for personal or organizational use.

OpenVPN’s flexibility and encryption ensure secure connections, whether you’re protecting data on public networks or enabling remote access for employees. By following these steps, you now have a functional and customizable VPN solution to bolster your online security.