How to Install and Configure OpenVPN Server on Ubuntu 22.04
How to Install and Configure OpenVPN Server on Ubuntu 22.04
Author: Łukasz Bodziony
Email: lukasz@bodziony.net.pl
Published: June 2025
Introduction
OpenVPN is a powerful open-source VPN solution that provides secure point-to-site and site-to-site connections. In this tutorial, Łukasz Bodziony will guide you through installing and configuring an OpenVPN server on Ubuntu 22.04 LTS.
Prerequisites
- Ubuntu 22.04 LTS server with sudo/root access
- At least 1 GB RAM (2 GB+ recommended)
- A public IP address or domain name pointing to your server
- Firewall allowing UDP port 1194
Step 1: Update and Install OpenVPN & Easy-RSA
sudo apt update && sudo apt upgrade -y
sudo apt install -y openvpn easy-rsa
Step 2: Set Up the Public Key Infrastructure (PKI)
make-cadir ~/openvpn-ca
cd ~/openvpn-ca
nano vars
In vars
, adjust the certificate defaults (e.g. KEY_COUNTRY
, KEY_ORG
), then:
source vars
./clean-all
./build-ca
Step 3: Generate Server Certificate & Keys
./build-key-server server
./build-dh
openvpn --genkey --secret keys/ta.key
Step 4: Configure the OpenVPN Service
sudo cp ~/openvpn-ca/keys/{server.crt,server.key,ca.crt,dh.pem,ta.key} /etc/openvpn
sudo gunzip -c /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz | sudo tee /etc/openvpn/server.conf
Edit /etc/openvpn/server.conf
and set:
port 1194
proto udp
dh dh.pem
tls-auth ta.key 0
cipher AES-256-CBC
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3
Step 5: Enable IP Forwarding & Firewall Rules
sudo nano /etc/sysctl.conf
# uncomment:
net.ipv4.ip_forward=1
sudo sysctl -p
Configure UFW:
sudo ufw allow 1194/udp
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status
Add NAT rules:
sudo ufw route allow in on tun0 out on eth0
sudo ufw reload
Step 6: Start and Enable OpenVPN
sudo systemctl enable openvpn-server@server
sudo systemctl start openvpn-server@server
sudo systemctl status openvpn-server@server
Step 7: Generate Client Configuration
cd ~/openvpn-ca
./build-key client1
Create a client config file client1.ovpn
combining certificates and keys, then distribute to clients.
Conclusion
Your OpenVPN server is now up and running on Ubuntu 22.04. You can connect remote clients securely using the generated .ovpn
profiles.
🚀 Host your OpenVPN on a fast, reliable VPS: netcloud24.com/servers/vps-linux/
Comments
Post a Comment