Creating Own VPN Server for External Users

Abstract: Solves the problem of securely allowing external users to access a private network by configuring an OpenVPN server on Linux with proper certificate management and firewall rules.

Created: 2026-08-24 by

Setting up an OpenVPN server allows external users to securely access your private network from anywhere. By configuring a Linux server with the OpenVPN software, generating cryptographic keys, and adjusting firewall rules, you create a robust tunnel that encrypts all traffic between the client and your internal resources.

Prerequisites and Server Setup

The foundation of any secure VPN relies on a stable operating system and the correct software packages. Most guides recommend using a Debian-based Linux distribution, such as Ubuntu or Debian, due to the extensive community support for OpenVPN. You will need root or sudo privileges to install necessary components and modify system configurations.

Begin by updating your package lists to ensure you are installing the latest stable versions. Run the standard update command followed by the installation of the openvpn package. On some systems, you may also need the easy-rsa suite to manage certificate authority tasks easily. This suite simplifies the generation of certificates and keys required for mutual authentication between the server and clients.

sudo apt-get update
sudo apt-get install openvpn easy-rsa

Once installed, verify the installation by checking the version of OpenVPN. This confirms that the binaries are accessible in your system path. Ensure that your server has a static IP address or a dynamic DNS service configured, as external users need a consistent endpoint to connect to.

Generating Certificates and Keys

Security in OpenVPN is driven by Public Key Infrastructure (PKI). You must generate a Certificate Authority (CA), server certificate, server key, and Diffie-Hellman parameters. These files prove the identity of both the server and the client, preventing unauthorized connections.

Navigate to the easy-rsa directory provided by your package manager. Initialize the PKI environment by running the initialization script. This creates the necessary directory structure for storing certificates and keys. Copy the sample variables file to a local configuration file so you can customize details like country, organization, and email addresses without modifying the source code.

cd /usr/share/easy-rsa
./easyrsa init-pki
cp vars.example vars
nano vars

After editing the variables, build the CA first. This step prompts you for a password which protects the CA key. Next, build the server certificate and key. When prompted, confirm the server name matches your server's hostname. Finally, generate the Diffie-Hellman parameters. This process can take several minutes depending on your server's speed, but it is critical for establishing secure key exchanges.

./easyrsa build-ca
./easyrsa build-server-full server nopass
./easyrsa gen-dh

You should also generate a client certificate and key pair. In a production environment, each user would have their own unique certificate. For this guide, we generate one generic client cert named client1. Remember to keep the ta.key secret; it provides additional TLS layer security against DDoS attacks.

./easyrsa build-client-full client1 tlsopenvpn --genkey --secret ta.key

Configuring the OpenVPN Server

With all cryptographic materials ready, the next step is configuring the server daemon. Copy the sample server configuration file from the /usr/share/doc/openvpn/examples/sample-config-files/ directory to your active configuration directory, typically /etc/openvpn/. Rename it to server.conf.

Edit server.conf to point to the generated certificates. Set the ca, cert, and key directives to the paths of your CA, server certificate, and server key respectively. Include the dh directive for the Diffie-Hellman file and the tls-auth directive for the ta.key. Uncomment the push "redirect-gateway def1 bypass-dhcp" line if you want all client traffic to route through the VPN, providing full privacy. However, note that this requires careful routing configuration as discussed in our article on routing traffic in VPN tunnels.

Ensure the port and proto settings match your network requirements. UDP is generally preferred for performance, while TCP offers better reliability over unstable connections. If you choose TCP, consider how it interacts with TLS encryption as noted in OpenVPN traffic through TLS-enabled TCP connection.

Firewall and Network Configuration

Your server's firewall must allow incoming connections on the OpenVPN port. If you are using UFW (Uncomplicated Firewall) on Ubuntu, enable OpenVPN by running ufw allow 1194/udp (or tcp if configured). It is crucial to also enable IP forwarding in the kernel. Edit /etc/sysctl.conf and uncomment the line net.ipv4.ip_forward=1. Apply the changes with sysctl -p.

If you are behind a NAT router, you must configure port forwarding on your router to direct traffic from the public IP on port 1194 to your internal server IP. Without this step, external users cannot reach your VPN server. Additionally, ensure that your ISP does not block VPN ports, as some providers restrict this traffic.

Starting the Service and Client Connection

Enable and start the OpenVPN service to make it persistent across reboots. Use systemctl enable openvpn@server and systemctl start openvpn@server. Check the status with systemctl status openvpn@server to ensure there are no errors during startup.

For the client, you need to bundle the client certificate, key, CA certificate, and ta.key into a single configuration file. Create a client.conf file that mirrors the server settings but points to the client-specific keys. Set the remote directive to your server's public IP or domain name. Transfer this file to your device and connect using the OpenVPN Connect application.

If you encounter connectivity issues where applications fail to connect through the tunnel, review your routing tables and DNS settings. Issues often stem from misconfigured push routes or local firewall rules blocking specific protocols. Refer to guides on programs failing to connect through OpenVPN for troubleshooting common client-side errors.

Frequently Asked Questions

Is an open port for VPN protected from hackers?

An open port itself is a potential entry point, but OpenVPN uses strong encryption and mutual authentication to secure the connection. Hackers cannot easily decrypt the traffic without the valid certificates and keys. However, exposing any service to the internet increases your attack surface, so keeping software updated and using strong passwords for the CA is essential. See our analysis on whether an open port for VPN is protected from hackers for more details.

Can I use the same certificate for multiple clients?

While technically possible, it is highly discouraged for security reasons. Each client should have a unique certificate to ensure non-repudiation and easier revocation if a device is lost. If one client's key is compromised, you only need to revoke that specific certificate rather than rebuilding the entire PKI infrastructure.

How do I prevent all traffic from going through the VPN?

To avoid routing all client traffic through the tunnel, remove or comment out the push "redirect-gateway def1 bypass-dhcp" line in the server configuration. Instead, use the push "route" directive to specify only the subnets you want clients to access via the VPN. This setup is ideal for remote access to specific internal resources without masking general internet activity.

What happens if my server restarts?

If you have enabled the systemd service as described, OpenVPN will automatically start when the server boots. Ensure that your firewall rules and IP forwarding settings are also set to persist across reboots. On Ubuntu, UFW rules persist by default, but sysctl changes require the configuration file modification shown earlier.

Why is my connection slow?

VPNs add overhead due to encryption and encapsulation. Using UDP instead of TCP usually results in lower latency and higher throughput. Additionally, the distance to the server and the bandwidth of the underlying internet connection play significant roles. If you are using a weak cipher or large key sizes, ensure your hardware can handle the cryptographic load efficiently.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More