How to Set Up an OpenVPN Server on Ubuntu 24.04
Learn how to set up an OpenVPN server on Ubuntu 24.04 LTS. Configure Easy-RSA CA, certificates, server daemon, IP forwarding, UFW NAT, and client profiles.

6 min read
Learn how to set up an OpenVPN server on Ubuntu 24.04 LTS. Configure Easy-RSA CA, certificates, server daemon, IP forwarding, UFW NAT, and client profiles.
- Prerequisites and Supported Releases
- Step 1: Updating System Packages and Installing OpenVPN and Easy-RSA
- Step 2: Setting Up the Easy-RSA Public Key Infrastructure (PKI)
OpenVPN is an industry-standard, open-source virtual private network (VPN) protocol engineered to create secure, point-to-point and site-to-site encrypted tunnels across untrusted networks. Utilizing custom security protocols based on OpenSSL and Transport Layer Security (TLS), OpenVPN provides military-grade encryption, flexible multi-factor authentication, granular subnet routing, and rock-solid defense against eavesdropping and packet inspection.
Hosting your own dedicated VPN server on Ubuntu eliminates reliance on third-party commercial VPN providers who may harvest browsing metadata or log network traffic. Understanding how to set up an openvpn server on ubuntu 24.04 allows network administrators and privacy-conscious users to tunnel untrusted public Wi-Fi connections, access remote home labs, and interconnect private cloud VPC networks.
In this comprehensive step-by-step tutorial, we demonstrate how to set up an OpenVPN server on Ubuntu 24.04 LTS (Noble Numbat). We cover installing OpenVPN and the Easy-RSA public key infrastructure (PKI) tool, creating a dedicated Certificate Authority (CA), issuing TLS certificates, configuring the OpenVPN server daemon in /etc/openvpn/server/, enabling Linux kernel IPv4 forwarding, configuring UFW NAT masquerading, and generating unified .ovpn client configuration profiles.
Step-by-step guide to installing and configuring a secure OpenVPN server on Ubuntu 24.04 LTS with Easy-RSA certificate authority, TLS encryption, UFW firewall NAT routing, and client .ovpn profiles.
Prerequisites and Supported Releases
This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat). The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.
Before proceeding, ensure you have the following requirements satisfied:
- A dedicated cloud server or VPS running
Ubuntu 24.04 LTS. - A non-root user account configured with administrative
sudoprivileges. - A static public IPv4 address assigned to the server.
- Uncomplicated Firewall (UFW) installed and active on the server.
Step 1: Updating System Packages and Installing OpenVPN and Easy-RSA
Begin by updating your local APT repository index and installing the OpenVPN daemon package alongside Easy-RSA.
Easy-RSA is a command-line public key infrastructure (PKI) management tool designed to generate root certificate authorities, issue digital certificates, and handle key signing requests.
Execute the following command to install openvpn and easy-rsa.
Verify that both packages install cleanly.
# Update repository indices and upgrade packages
sudo apt update && sudo apt upgrade -y
# Install OpenVPN and Easy-RSA
sudo apt install -y openvpn easy-rsa
Step 2: Setting Up the Easy-RSA Public Key Infrastructure (PKI)
To maintain maximum security, manage your Public Key Infrastructure (PKI) in a dedicated directory. Create an Easy-RSA working directory in your user home folder and initialize the PKI.
Copy the template Easy-RSA configuration file into ~/openvpn-ca/vars and define your certificate parameter defaults.
Initialize the PKI directory and build the Certificate Authority (CA) root certificate and private key.
Assign a strong passphrase to the CA root private key.
# Create PKI working directory
make-cadir ~/openvpn-ca
cd ~/openvpn-ca
# Initialize PKI environment
./easyrsa init-pki
# Build the Certificate Authority (prompts for CA passphrase)
./easyrsa build-ca nopass
# Verify generated CA certificate
ls -l pki/ca.crt
Step 3: Generating the OpenVPN Server Certificate and Private Key
Next, generate the server's private key and certificate signing request (CSR), then sign the request using your newly created Certificate Authority.
Use the nopass option so that the OpenVPN server daemon can start automatically upon system boot without requiring an administrator to manually type a passphrase.
Sign the server certificate request as a server entity.
Copy the generated server certificate, private key, and root CA certificate into the OpenVPN server configuration directory at /etc/openvpn/server/.
# Generate server private key and certificate request without passphrase
cd ~/openvpn-ca
./easyrsa gen-req server nopass
# Sign the server certificate with the CA
./easyrsa sign-req server server
# Copy server keys and CA certificate to /etc/openvpn/server/
sudo cp pki/ca.crt /etc/openvpn/server/
sudo cp pki/issued/server.crt /etc/openvpn/server/
sudo cp pki/private/server.key /etc/openvpn/server/
Step 4: Generating Diffie-Hellman Parameters and HMAC TLS Signature
To fortify the OpenVPN cryptographic exchange, generate Diffie-Hellman parameters used for perfect forward secrecy (PFS).
Furthermore, generate a shared HMAC signature key (tls-crypt) to authenticate all SSL/TLS handshake packets before processing, protecting your OpenVPN server against port scanning, DoS floods, and unauthorized TLS handshakes.
Execute the following commands to generate and position these cryptographic assets in /etc/openvpn/server/.
# Generate Diffie-Hellman parameters
cd ~/openvpn-ca
./easyrsa gen-dh
sudo cp pki/dh.pem /etc/openvpn/server/
# Generate shared tls-crypt HMAC signature key
openvpn --genkey secret /etc/openvpn/server/tc.key
Step 5: Configuring the OpenVPN Server Daemon
Copy the sample OpenVPN server configuration into /etc/openvpn/server/server.conf and customize it for production routing.
Configure the server to listen on UDP port 1194, assign virtual IP addresses in the 10.8.0.0/24 subnet, push DNS resolvers (such as Cloudflare 1.1.1.1 and Google 8.8.8.8), and push the redirect-gateway def1 bypass-dhcp directive to route all client internet traffic through the VPN tunnel.
Drop root privileges by configuring the unprivileged nobody user and nogroup group.
# Create /etc/openvpn/server/server.conf
sudo bash -c 'cat <<EOF > /etc/openvpn/server/server.conf
port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh.pem
tls-crypt tc.key
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist /var/log/openvpn/ipp.txt
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 1.1.1.1"
push "dhcp-option DNS 8.8.8.8"
keepalive 10 120
cipher AES-256-GCM
auth SHA256
user nobody
group nogroup
persist-key
persist-tun
status /var/log/openvpn/openvpn-status.log
verb 3
explicit-exit-notify 1
EOF'
# Create log directory
sudo mkdir -p /var/log/openvpn
Step 6: Enabling Kernel IPv4 Packet Forwarding
For the OpenVPN server to route client traffic to the internet, you must enable packet forwarding in the Linux kernel.
Create a sysctl configuration file at /etc/sysctl.d/99-openvpn.conf and set net.ipv4.ip_forward = 1.
Apply the sysctl configuration immediately without rebooting the system.
# Enable IPv4 packet forwarding in sysctl
echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/99-openvpn.conf
# Load the configuration
sudo sysctl -p /etc/sysctl.d/99-openvpn.conf
# Verify kernel forwarding parameter
cat /proc/sys/net/ipv4/ip_forward
Step 7: Configuring UFW Firewall NAT and Routing Rules
To translate OpenVPN virtual client IP addresses (10.8.0.0/24) into the server's public IP address, configure Network Address Translation (NAT / IP masquerading) in UFW.
First, identify your primary public network interface (e.g., eth0, ens3, or enp1s0) using ip route.
Edit /etc/ufw/before.rules to add the NAT table POSTROUTING masquerade rule, permit packet forwarding in /etc/default/ufw, allow UDP port 1194, and reload UFW.
# Detect public interface name
DEFAULT_IFACE=$(ip route show default | awk '{print $5}')
echo "Public Interface: $DEFAULT_IFACE"
# Allow OpenVPN UDP port 1194 in UFW
sudo ufw allow 1194/udp comment 'OpenVPN Server'
# Configure UFW default forward policy to ACCEPT in /etc/default/ufw
sudo sed -i 's/DEFAULT_FORWARD_POLICY="DROP"/DEFAULT_FORWARD_POLICY="ACCEPT"/' /etc/default/ufw
# Prepend NAT table rules to /etc/ufw/before.rules
sudo sed -i "1i# START OPENVPN RULES\n*nat\n:POSTROUTING ACCEPT [0:0]\n-A POSTROUTING -s 10.8.0.0/24 -o $DEFAULT_IFACE -j MASQUERADE\nCOMMIT\n# END OPENVPN RULES\n" /etc/ufw/before.rules
# Reload UFW to apply NAT routing
sudo ufw reload
Step 8: Starting the OpenVPN Service and Generating Client .ovpn Profile
Enable and start the OpenVPN server systemd service using the systemd template unit [email protected].
Next, generate a client certificate pair (e.g., client1) and bundle the root CA certificate, client certificate, client private key, and tc.key into a single, unified .ovpn client profile.
Download the .ovpn file to your client device (Windows, macOS, Linux, iOS, or Android) and connect using an OpenVPN client.
# Enable and start the OpenVPN server service
sudo systemctl enable --now [email protected]
# Verify service status
sudo systemctl status [email protected] --no-pager
# Generate client certificate without passphrase
cd ~/openvpn-ca
./easyrsa gen-req client1 nopass
./easyrsa sign-req client client1
# Generate unified client1.ovpn profile file
KEY_DIR=/etc/openvpn/server
OUTPUT_DIR=~/client-configs
mkdir -p $OUTPUT_DIR
cat << EOF > $OUTPUT_DIR/client1.ovpn
client
dev tun
proto udp
remote <YOUR_SERVER_PUBLIC_IP> 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
cipher AES-256-GCM
auth SHA256
key-direction 1
<ca>
$(cat $KEY_DIR/ca.crt)
</ca>
<cert>
$(cat ~/openvpn-ca/pki/issued/client1.crt)
</cert>
<key>
$(cat ~/openvpn-ca/pki/private/client1.key)
</key>
<tls-crypt>
$(sudo cat $KEY_DIR/tc.key)
</tls-crypt>
EOF
echo "Generated unified client profile at: $OUTPUT_DIR/client1.ovpn"
Troubleshooting and Common Errors
When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:
Client connects successfully but cannot browse the internet (no web pages load)
Resolution: This indicates IPv4 packet forwarding or UFW NAT masquerading is misconfigured. Verify that cat /proc/sys/net/ipv4/ip_forward returns 1. Ensure /etc/ufw/before.rules includes the -A POSTROUTING -s 10.8.0.0/24 -o -j MASQUERADE rule pointing to your active network interface.
OpenVPN service fails to start with 'Cannot open /etc/openvpn/server/tc.key'
Resolution: Verify file ownership and permissions on cryptographic keys. The server.key and tc.key files must be readable by root upon service initialization: sudo chmod 600 /etc/openvpn/server/*.key.
Client connection handshake times out with 'TLS Error: TLS key negotiation failed'
Resolution: Confirm that UDP port 1194 is open in both UFW (sudo ufw status) and your cloud provider's external security group (AWS Security Group, GCP Firewall, or DigitalOcean firewall).
Security Best Practices and Hardening
Always generate a distinct certificate and private key for each individual client device; never share a single client certificate among multiple users.
If a client device or laptop is lost or compromised, immediately revoke its certificate using './easyrsa revoke client_name' and update the CRL (Certificate Revocation List).
Protect your CA root private key (~/openvpn-ca/pki/private/ca.key) with strict file permissions (chmod 600) or store it offline.
Utilize modern AES-256-GCM encryption ciphers and keep the OpenVPN package updated with regular security patches.
Related Ubuntu Tutorials and Documentation
Deepen your Linux system administration skills with our related production-tested guides:
Authoritative References and Official Documentation

UNIX and Linux System Administration Handbook, 5th Edition
Frequently Asked Questions
Quick answers to common questions and configurations
.ovpn profile file provides instant one-tap encrypted connections../easyrsa revoke client_name followed by ./easyrsa gen-crl. Copy the updated crl.pem file to /etc/openvpn/server/crl.pem and add crl-verify crl.pem to your server.conf.Editorial Disclosure: Website Vidya is supported by our readers. When you purchase hosting, tools, or software through our verified partner links, we may earn an affiliate commission at no extra cost to you. We only recommend solutions we trust and rigorously verify.
Rajesh Ray
I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.
Most Read Guides
TrendingUbuntu Server Not Booting? 10 Simple Steps to Fix It Fast
How to Create a 3D Button in HTML and CSS: Easy Steps
How to Install Python and Pip on Ubuntu 24.04 LTS
How to Install Nginx on Ubuntu 24.04
How to Install Python on Ubuntu 24.04 LTS
Related Technical Guides
Tested runbooks, server administration walkthroughs, and troubleshooting guides

Join the Conversation & Perspective
Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.
No comments on this guide yet. Be the first to share your thoughts or ask a question!