Skip to content

Installing OpenVPN on Ubuntu the right way

A production OpenVPN install on Ubuntu — packages, PKI bootstrap, server config, firewall, and the operational checks an MSP runs before issuing the first client profile.

A fresh Ubuntu box, a public IP, and a directive to “stand up a VPN so the team can reach internal services.” This article walks the install we run in production: get the OpenVPN package on, bootstrap a real PKI with Easy-RSA, write a server config that does not embarrass the box, open the firewall narrowly, and confirm a client can tunnel through. The goal is not “OpenVPN is listening” — it is “OpenVPN is listening, certificates are tracked, and a client profile actually works.”

How to verify

Before touching the package manager, check what is already there. A base image may have stale OpenVPN bits, and port 1194/udp may be claimed by another service.

ss -lunp | grep -E ':1194\b'
dpkg -l | grep -E 'openvpn|easy-rsa'
ip route show default
sysctl net.ipv4.ip_forward

If net.ipv4.ip_forward is 0, the box will accept the tunnel but refuse to route — you will see clients connect and then nothing routes to LAN. Note the default interface name (eth0, ens3, etc.) before you write firewall rules.

What’s happening

OpenVPN on Ubuntu ships as the openvpn package and the companion easy-rsa package for certificate management. The server runs as a long-lived process bound to UDP (or TCP) 1194, accepts inbound TLS handshakes from clients that present a certificate signed by your CA, and assigns each authenticated client an IP from a configured subnet on a virtual tun0 interface. The kernel then forwards packets between tun0 and the physical interface based on iptables / nftables NAT rules and ip_forward.

The PKI is the whole game. Easy-RSA produces a CA certificate, a server certificate signed by the CA, a Diffie-Hellman parameter file (or short-cuts via TLS-crypt), and per-client certificates. Lose track of which client cert is issued to whom and you will not be able to revoke cleanly when a laptop walks off. We treat the PKI directory as a first-class asset: backed up, audited, and never on the VPN server itself in long-running deployments.

The procedure

  1. Install packages.

    apt update
    apt install -y openvpn easy-rsa ufw
  2. Bootstrap the PKI. Do this on a separate admin host in real engagements; the example below shows the inline form for brevity.

    make-cadir /etc/openvpn/easy-rsa
    cd /etc/openvpn/easy-rsa
    ./easyrsa init-pki
    ./easyrsa --batch build-ca nopass
    ./easyrsa --batch gen-req server nopass
    ./easyrsa --batch sign-req server server
    ./easyrsa gen-dh
    openvpn --genkey secret /etc/openvpn/tls-crypt.key
  3. Install certificates into the server config dir.

    install -m 600 pki/ca.crt              /etc/openvpn/server/
    install -m 600 pki/issued/server.crt   /etc/openvpn/server/
    install -m 600 pki/private/server.key  /etc/openvpn/server/
    install -m 600 pki/dh.pem              /etc/openvpn/server/
    install -m 600 /etc/openvpn/tls-crypt.key /etc/openvpn/server/
  4. Write /etc/openvpn/server/server.conf. Minimum viable, production-shaped:

    port 1194
    proto udp
    dev tun
    ca /etc/openvpn/server/ca.crt
    cert /etc/openvpn/server/server.crt
    key /etc/openvpn/server/server.key
    dh /etc/openvpn/server/dh.pem
    tls-crypt /etc/openvpn/server/tls-crypt.key
    topology subnet
    server 10.8.0.0 255.255.255.0
    push "redirect-gateway def1 bypass-dhcp"
    push "dhcp-option DNS 10.8.0.1"
    keepalive 10 120
    cipher AES-256-GCM
    data-ciphers AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305
    auth SHA256
    user nobody
    group nogroup
    persist-key
    persist-tun
    status /var/log/openvpn/openvpn-status.log
    log-append /var/log/openvpn/openvpn.log
    verb 3
    explicit-exit-notify 1
  5. Enable forwarding and NAT.

    sed -i 's/^#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf
    sysctl -p
    iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
    iptables-save > /etc/iptables/rules.v4
  6. Open the firewall.

    ufw allow 1194/udp
    ufw allow OpenSSH
    ufw enable
  7. Start and enable the unit.

    systemctl enable --now openvpn-server@server.service
    journalctl -u openvpn-server@server -e --no-pager | tail -40

Common pitfalls

  • Forgetting net.ipv4.ip_forward=1 — clients connect, get an IP, and then nothing routes; symptom is ping 10.8.0.1 works but nothing past it.
  • Running the daemon as root with no user nobody directive — works fine until you read the audit report.
  • Skipping tls-crypt — UDP 1194 is now visible to every internet scanner; tls-crypt makes the handshake opaque and dramatically reduces noise.
  • Reusing server.key across rebuilds without revoking — every old client still validates. Build a fresh CA when in doubt.
  • Logging to /var/log/syslog only — without status and log-append, you cannot answer “which user was on the VPN at 14:32 yesterday?”

In the engagements we run, the OpenVPN server is a documented piece of infrastructure with a tracked PKI, a revocation procedure, and an on-call runbook for “VPN is down.” This is the kind of work Stack Harbor handles as part of our Managed Operations — the install above is the first hour; the next hundred hours are rotation, monitoring, and the part that actually keeps the team productive.