OpenVPN is open-source VPN software. It builds an encrypted tunnel between your devices and a server you control, and uses TLS to authenticate both ends. This guide sets up an OpenVPN server on Ubuntu Server with openvpn-install, a script by Angristan that installs OpenVPN and writes its configuration, certificates and firewall rules for you. Then it covers connecting your devices, adding and revoking clients, and the other ways to run OpenVPN on Ubuntu.
With your own VPN server, the network you're on, such as public Wi-Fi, can't read your traffic, and websites see the server's IP address instead of yours. It doesn't make you anonymous, though: the sites you sign in to still know who you are.
What you need
- A server running Ubuntu Server with a public IP address, which you log in to over SSH as root or with sudo. A LyraHosting Linux VPS comes with full root access and a dedicated IPv4 address, with IPv6 on request; a dedicated server gives you a whole physical machine.
- The TUN device. OpenVPN needs it, and the installer stops if it's missing. Each LyraHosting Linux VPS is a KVM virtual machine with its own kernel. On container-based VPS types such as OpenVZ, the provider has to enable TUN for you. On our Storage VPS, which runs on OpenVZ, TUN is available.
- An OpenVPN app on each device you want to connect.
Traffic from your VPN devices goes out to the internet from your server's IP address, so, like everything else on the server, it must be legal and follow our Acceptable Use Policy. You install and run the VPN yourself.
Which Ubuntu version to use
Use an Ubuntu LTS release that still gets standard security updates. Ubuntu's release pages give these dates for the end of standard support:
- Ubuntu 26.04 LTS: May 2031;
- Ubuntu 24.04 LTS: 2029;
- Ubuntu 22.04 LTS: 2027;
- Ubuntu 20.04 LTS: ended in May 2025;
- Ubuntu 18.04 LTS: ended in 2023.
After that, a release gets security fixes only through Ubuntu Pro, which Canonical offers free for personal use on up to five machines.
The installer's README lists Ubuntu 18.04 and newer, and its automated tests run on 18.04, 20.04, 22.04, 24.04 and 25.10. For a new VPN server, Ubuntu 24.04 LTS is a good choice: it's in those tests and supported until 2029. Ubuntu 26.04 LTS is supported for longer, but wasn't in the installer's tests yet on November 3, 2026. If your server still runs 18.04 or 20.04, upgrade it to a supported LTS release first. To see which release you run:
lsb_release -a What the installer does
openvpn-install is a Bash script, published on GitHub under the MIT license. It's a community project, not part of Ubuntu or OpenVPN. In plain words, it:
- installs OpenVPN, from the official OpenVPN repository when it has packages for your Ubuntu release, or else from Ubuntu's own packages;
- creates a certificate authority and certificates for the server and each client, with Easy-RSA;
- writes the server configuration to
/etc/openvpn/server/and runs it as the systemd serviceopenvpn-server@server; - turns on IP forwarding and adds firewall rules that open the VPN port and let VPN traffic out to the internet through NAT: with firewalld or nftables if that service is active, and otherwise with iptables rules managed by a service called
iptables-openvpn; - writes a
.ovpnfile for each client, with everything that device needs to connect.
Its defaults are UDP port 1194, the AES-128-GCM cipher, ECDSA certificates, TLS 1.2 or newer, and tls-crypt-v2, which encrypts the connection setup with a separate key for every client. It no longer offers compression, which it had advised against because of the VORACLE attack. It can also remove everything it set up, firewall rules included.
Step 1: Update the server
Log in over SSH and install all pending updates:
sudo apt update
sudo apt full-upgrade When an update, such as a new kernel, needs a restart, Ubuntu creates the file /run/reboot-required. Check for it:
ls /run/reboot-required If it exists, restart with sudo reboot and log in again after a minute or two. If the server doesn't come back, the control panel of a LyraHosting Linux VPS can reboot it or start the rescue system, and every LyraHosting dedicated server includes IPMI.
Step 2: Download the script
Download the script from the project's master branch and make it executable. If curl is missing, install it with sudo apt install curl.
curl -O https://raw.githubusercontent.com/angristan/openvpn-install/master/openvpn-install.sh
chmod +x openvpn-install.sh The script runs as root and changes your firewall, so read it first, for example with less openvpn-install.sh. Its README warns that commands and options can change between versions: if you automate installs, use a specific commit instead of master.
Step 3: Run the installer
The current script takes a command: run without one, it only shows its help, so the bare ./openvpn-install.sh of older guides no longer starts the setup. For the guided setup, start interactive mode as root:
sudo ./openvpn-install.sh interactive It checks that it runs as root and that the TUN device exists, then asks its questions. Press Enter to keep a default:
- Server address. It shows the addresses it found, asks whether clients connect over IPv4 or IPv6, and confirms the address to listen on. If the server is behind NAT, it asks for the public address or a hostname. On a server with its own public IPv4 address, keep the defaults. To check your addresses, run
ip -brief address. - Client addresses. Whether VPN clients get IPv4, IPv6 or both (choose IPv6 only if the server has working IPv6), and their private range, 10.8.0.0/24 by default.
- What clients can reach. Send their internet traffic through the VPN (yes by default), reach each other (no) and reach the server's local network (no; mainly for VPN servers at home).
- Port and protocol. Port 1194 by default, your own, or a random one. UDP is faster, and the script recommends it; TCP can get through networks that block UDP, such as some hotel or office networks. If you pick TCP port 443, make sure no web server on this machine uses it.
- DNS. The resolvers your devices use while connected: the server's own, a self-hosted Unbound resolver, or a public service such as Cloudflare (the default), Quad9 or AdGuard DNS.
- Profile sharing, MTU and authentication. Keep the defaults: one device per profile, MTU 1500, and PKI with a certificate authority. Peer fingerprint mode is simpler but needs OpenVPN 2.6 or newer.
- Encryption settings. Answer
nto keep the defaults, which the script describes as safe. To connect an older router or app, answeryand choose tls-auth for the control channel: the default, tls-crypt-v2, is an OpenVPN 2.5 feature.
It then installs OpenVPN and creates the first client. It asks for a name made of letters, numbers, underscores or dashes, such as laptop; how many days the certificate is valid (3650 by default); and whether to protect the file with a password. With a password, the private key in the file is encrypted and your app asks for it when you connect; without one, the file alone is enough.
To install with the defaults and no questions, run sudo ./openvpn-install.sh install instead. It creates a first client called client. Options change the defaults, such as --port 443 --protocol tcp or --client laptop, and ./openvpn-install.sh install --help lists them all.
Then check that the server is running. The status should say active (running); if it doesn't, the log shows why:
sudo systemctl status openvpn-server@server
sudo journalctl -u openvpn-server@server Step 4: Check your firewall
The installer opens the VPN port in the firewall it manages, but it doesn't touch ufw, Ubuntu's firewall tool, which is off by default. Check whether ufw is on:
sudo ufw status If it says Status: active, allow the port and protocol you chose, here UDP port 1194:
sudo ufw allow 1194/udp If you want to turn ufw on, allow SSH first. Enabling ufw over SSH can drop your connection, and without a rule for SSH you're locked out. If SSH listens on a port other than 22, use that port:
sudo ufw allow 22/tcp
sudo ufw allow 1194/udp
sudo ufw enable ufw's default policy denies forwarded traffic. If devices connect but can't reach the internet while ufw is on, check its forwarding settings first; Ubuntu's firewall documentation explains them.
Step 5: Connect a device
The installer prints where it saved the client file: by default <name>.ovpn in your home directory, such as /home/youruser/laptop.ovpn when you used sudo, or /root/laptop.ovpn as root. Copy it to your computer, for example with scp (203.0.113.10 is an example address; use your server's):
scp youruser@203.0.113.10:laptop.ovpn . Then import it into an OpenVPN app. The installer's README suggests the official OpenVPN community client on Windows; Tunnelblick, Viscosity or OpenVPN Connect on macOS; OpenVPN for Android; OpenVPN Connect on iOS; and on Linux the openvpn package, with sudo openvpn --config laptop.ovpn.
The file contains the client's private key, so treat it like a password: don't send it by unencrypted email or leave it on shared storage, and give every device its own client. Once you're connected, a "what is my IP" search should show your server's address, and a DNS leak test, as the installer's FAQ suggests, should show the DNS servers you chose rather than your internet provider's.
How to add, list and revoke clients
sudo ./openvpn-install.sh client add phone
sudo ./openvpn-install.sh client add tablet --password
sudo ./openvpn-install.sh client list
sudo ./openvpn-install.sh client revoke phone client addcreates a client and its.ovpnfile; with--password, it asks for a password that protects the key.client listshows each certificate, whether it's valid or revoked, and when it expires.client revokerevokes the certificate, deletes the client's.ovpnfile from the home directories on the server and disconnects the device if it's online. Use it when a device is lost or someone should no longer have access.client renewrenews a certificate and writes a new file, which you copy to the device again.
sudo ./openvpn-install.sh server status lists the connected clients, refreshed every 60 seconds. On a server where OpenVPN is installed, sudo ./openvpn-install.sh interactive opens a menu with the same tasks.
Keep it up to date
OpenVPN updates with the rest of the system when you run sudo apt update and sudo apt upgrade. The script can't update an existing installation: for a newer version of it, its FAQ says to uninstall and install again. Uninstalling removes OpenVPN, its configuration and its firewall rules, so your devices then need new client files:
sudo ./openvpn-install.sh uninstall Other ways to run OpenVPN on Ubuntu
- By hand, with Ubuntu's packages. Ubuntu's server documentation installs
openvpnandeasy-rsawith apt and walks through the certificate authority, the server configuration and IP forwarding. It's more work, and you add the NAT and firewall rules yourself. - OpenVPN Access Server. OpenVPN Inc.'s own server, with a web admin interface on port 943. OpenVPN's guide for Ubuntu explains the install, with a command you copy from the Access Server portal. It supports Ubuntu 22.04, 24.04 and 26.04 LTS, and allows two connections without a license.
- WireGuard. The installer's author notes that WireGuard is simpler and faster for most uses, and maintains a similar wireguard-install script. OpenVPN still makes sense when you need TCP, password-protected keys or clients on older systems.



