Server AdministrationUpdated November 24, 2026·5 min read

How to Set Up an OpenVPN Server on Ubuntu

Before you install OpenVPN on Ubuntu, take one minute to answer a question that most tutorials do not address: do you really want to use OpenVPN? OpenVPN is mature and highly versatile, although it requires a small certificate authority as well as more configuration than the newer WireGuard. Below you can see the comparison and then the full server setup for OpenVPN.

OpenVPN or WireGuard?

OpenVPN WireGuard
Setup effort Certificate authority, server config, client profiles One key pair per device, a short config
Runs over UDP or TCP, any port UDP only
Gets through strict firewalls Yes, can run on TCP 443 Less often
Speed Good Usually faster, runs in the kernel
Choose it when You need TCP, existing OpenVPN clients, or certificate-based access control You control both ends and want the simplest fast tunnel

Does WireGuard fit? Then sudo apt install wireguard is the shortcut way to go. Need OpenVPN? Well continue then. OpenVPN v 2.6 is readily available on Ubuntu 24.04.

Install OpenVPN on Ubuntu: the build at a glance

  1. Install the OpenVPN and easy-rsa packages.
  2. Establish the Certificate Authority (CA).
  3. Issue the server certificate and key pair.
  4. Create the OpenVPN server configuration file.
  5. Configure routing and NAT.
  6. Launch the OpenVPN server.
  7. Issue the client certificate and profile.

From step 2 until the end, all these actions are performed in root shell (sudo -i). All actions related to the creation of certificates should be conducted in CA folder.

1. Install the packages

sudo apt update
sudo apt install openvpn easy-rsa

The EasyRSA tool is what's needed to generate and sign certificates that OpenVPN needs.

2. Create the certificate authority

sudo make-cadir /etc/openvpn/easy-rsa
sudo -i
cd /etc/openvpn/easy-rsa
./easyrsa init-pki && ./easyrsa build-ca

Password is needed for build-ca. It protects the CA’s private key, which is able to sign any certificate; therefore, select a reliable password.

3. Server certificate and keys

./easyrsa gen-req myservername nopass
./easyrsa gen-dh
./easyrsa sign-req server myservername
cp pki/dh.pem pki/ca.crt pki/issued/myservername.crt pki/private/myservername.key /etc/openvpn/
cd /etc/openvpn
openvpn --genkey secret ta.key

In ta.key there is one more shared secret added to protect packets, as the server will simply ignore all packets without this secret key which makes scans and denial-of-service attempts much harder.

4. Server configuration

Start from Ubuntu's sample file:

cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf /etc/openvpn/myserver.conf

In /etc/openvpn/myserver.conf, direct ca, cert, key and dh line entries to the files you copied, but keep the ta.key entry unchanged. In order to ensure that all the Internet data from your client passes through the VPN tunnel, uncomment:

push "redirect-gateway def1 bypass-dhcp"

Then provide a DNS server to your clients using a push "dhcp-option DNS ..." line. Use default settings of port 1194 and proto udp unless a firewall forces you to use TCP.

5. Forwarding and NAT

The server must forward packets from the VPN clients to the Internet:

echo "net.ipv4.ip_forward = 1" | tee /etc/sysctl.d/50-enable-ipv4-forwarding.conf
sysctl -p /etc/sysctl.d/50-enable-ipv4-forwarding.conf

The clients will be receiving IP addresses from the subnet 10.8.0.0/24 provided by the example config, hence NAT has to be done for this traffic on its way out. Find your public interface: it is the name after dev on the default line of ip route. Then:

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

Replace eth0 with your interface name. You will lose this rule when you reboot; however, you can save it with the iptables-persistent package or include this rule in the NAT section of /etc/ufw/before.rules if you use ufw. Allow access to your VPN port: ufw allow 1194/udp.

6. Start the server

The systemd unit takes the config file name:

systemctl enable --now openvpn@myserver
journalctl -u openvpn@myserver -xe

However, systemctl start openvpn cannot directly start your server, since it’s the @myserver part that actually loads myserver.conf.

7. The first client

Go back to the CA’s directory and issue a certificate for the device:

cd /etc/openvpn/easy-rsa
./easyrsa gen-req myclient1 nopass && ./easyrsa sign-req client myclient1

pki/ca.crt, pki/issued/myclient1.crt, pki/private/myclient1.key, and ta.key are the four files that are needed on your end. Copy the client.conf file from the same examples folder and change its remote entry to your server's IP and port. Combine the four files, or their content, into an .ovpn file, and move it over SSH, never by email.

When it does not connect

Symptom Likely cause
Client times out UDP 1194 blocked by a firewall on either side
Connects, but no internet Forwarding or the NAT rule is missing, or the wrong interface name
TLS handshake failed ta.key missing or mismatched on one side
Service exits at start A file path in myserver.conf is wrong; check the journal

Our tool Linux network commands cheat sheet would assist you in verifying routes and the listening ports on the server.

Where to put the VPN server

A VPN adds the distance to the server to every connection you make, hence position it near you or near the services you want to access. The latency checker measures round-trip time from each OrbitServers location to your connection, while the looking glass runs network tests from our network. A good choice for a VPN in a small team is the OrbitServers VPS.

Was this article helpful?

Written by Julius · Product Manager