OpenVPN is free, open-source VPN software that creates an encrypted tunnel between a device and a network, so you can reach your home or office network securely from anywhere, or protect your traffic on public Wi-Fi. It uses TLS, the same technology behind HTTPS, and certificates to prove who is connecting, and it runs on almost every operating system.
OpenVPN has been around since 2001, and it’s still one of the most widely used VPNs in the world. Businesses use it for remote access, home-lab fans use it to reach their servers, and many commercial VPN services give their customers OpenVPN configuration files. Newer options like WireGuard are faster and simpler, but OpenVPN’s flexibility and its ability to work through strict firewalls keep it relevant.
This guide explains what OpenVPN is, how it works, how it compares with the alternatives, and how to set up your own OpenVPN server on Linux, step by step. Every configuration in this guide was tested with a working server and client.
What Is a VPN?
A virtual private network (VPN) creates an encrypted connection, called a tunnel, between your device and another network. Everything you send through the tunnel is scrambled, so people on the same coffee-shop Wi-Fi or your internet provider can’t read it, and your device acts as if it were plugged into the network on the other end. The networking concepts guide covers VPNs alongside CDNs and other building blocks.
People use VPNs for three main jobs:
- Remote access: reach a home or office network from anywhere, for example a file server, a NAS, or a computer you manage.
- Privacy on untrusted networks: encrypt everything on public Wi-Fi in hotels, airports, and cafés.
- Site-to-site connections: join two office networks as if they were one.
The Different Things Called “OpenVPN”
The name covers a few related products:
| Product | What it is | Cost |
|---|---|---|
| OpenVPN Community Edition | The original open-source software (client and server) | Free |
| OpenVPN Connect | The official client app for Windows, macOS, iOS, and Android | Free |
| OpenVPN Access Server | A self-hosted server with a web admin interface, from OpenVPN Inc. | Free for 2 connections at a time, then paid |
| CloudConnexa | A hosted VPN and zero-trust service from OpenVPN Inc. | Free tier, then paid |
This guide uses the Community Edition server and the OpenVPN Connect client.
How OpenVPN Works
- TLS and certificates. When a client connects, OpenVPN uses TLS to check the server’s certificate and the client’s certificate, both signed by your own certificate authority (CA). Only devices with a certificate from your CA can connect, and you can revoke a certificate if a device is lost.
- Two channels. A control channel handles the TLS handshake and key exchange. A separate data channel carries your actual traffic, encrypted with modern ciphers like AES-256-GCM or ChaCha20-Poly1305.
- A virtual network interface. OpenVPN creates a virtual network card on each side. A tun interface carries IP traffic (the usual choice); a tap interface acts like a full Ethernet connection (rarely needed).
- UDP or TCP. OpenVPN normally uses UDP port 1194. It can also use TCP, for example on port 443, the HTTPS port, which helps on networks that block everything except web traffic. UDP is faster; use TCP only when you have to. See the well-known port numbers for more on ports.
- An extra shield: tls-crypt. A shared key encrypts and authenticates even the handshake, so the server ignores anyone who doesn’t have it. That hides the server from port scanners and protects against some attacks on TLS itself.
Recent versions also support data channel offload (DCO), which moves encryption into the operating system’s kernel for much better speed on Linux and Windows.
OpenVPN vs. WireGuard vs. Tailscale
| OpenVPN | WireGuard | Tailscale | |
|---|---|---|---|
| Released | 2001 | 2020 (in the Linux kernel) | 2019 (built on WireGuard) |
| Setup | Moderate: certificates and config files | Simple: key pairs and a short config | Easiest: sign in on each device |
| Speed | Good, better with DCO | Very fast | Very fast |
| Works through strict firewalls | Yes, over TCP 443 | UDP only | Yes, with relays |
| Authentication | Certificates, plus optional passwords or MFA | Keys | Your identity provider (Google, Microsoft, and others) |
| Best for | Flexible, traditional remote access; compatibility | Fast, simple tunnels you manage yourself | The easiest secure access between your own devices |
If you just want to reach your home network from your phone, Tailscale is the quickest path. Choose OpenVPN when you want a traditional VPN server you fully control, need TCP to get through restrictive networks, need to support devices or organizations that already standardize on OpenVPN, or want certificate-based access with revocation.
Set Up Your Own OpenVPN Server
This walkthrough builds a full-tunnel VPN: once connected, all of a client’s internet traffic goes through your server. It uses Ubuntu or Debian; other Linux distributions are similar.
What You Need
- A Linux server or virtual machine that’s always on, at home or in the cloud. A Raspberry Pi works too.
- Administrator (
sudo) access. The Linux terminal guide covers the basics. - A public IP address or a domain name for your network. If your home IP changes, use a dynamic DNS service.
- Access to your router or cloud firewall to open UDP port 1194.
Step 1: Install OpenVPN and Easy-RSA
sudo apt update
sudo apt install openvpn easy-rsa
Easy-RSA is a small tool for creating your certificate authority and certificates.
Step 2: Create Your Certificate Authority and Certificates
Create a folder for your CA and build the certificates:
make-cadir ~/openvpn-ca
cd ~/openvpn-ca
./easyrsa init-pki
./easyrsa build-ca
./easyrsa build-server-full server nopass
./easyrsa build-client-full laptop nopass
openvpn --genkey secret ta.key
What each command does:
init-pkicreates an empty folder structure (pki/) for keys and certificates.build-cacreates your certificate authority. It asks for a passphrase, which protects the CA’s private key, and a name for the CA. Choose a strong passphrase; anyone with the CA key can create valid certificates.build-server-full server nopasscreates and signs the server’s certificate.nopassmeans the server’s key has no passphrase, so the service can start on its own.build-client-full laptop nopasscreates a certificate for one device. Make one per device (laptop,phone,tablet), so you can revoke a single device later.openvpn --genkey secret ta.keycreates the shared tls-crypt key.
Step 3: Copy the Server Files
sudo cp pki/ca.crt pki/issued/server.crt pki/private/server.key ta.key /etc/openvpn/server/
Keep pki/private/ca.key out of this folder. It never needs to be on the VPN server’s configuration path, and ideally it would live on a different, offline computer.
Step 4: Write the Server Configuration
Create /etc/openvpn/server/server.conf:
port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh none
tls-crypt ta.key
topology subnet
server 10.8.0.0 255.255.255.0
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 1.1.1.1"
keepalive 10 120
user nobody
group nogroup
persist-key
persist-tun
verb 3
The important lines:
port 1194,proto udp,dev tun: listen on UDP port 1194 and create a routed tunnel.ca,cert,key,tls-crypt: the files from Step 3.dh none: use modern elliptic-curve key exchange instead of an old-style Diffie-Hellman file.server 10.8.0.0 255.255.255.0: clients get addresses from this private range; the server is10.8.0.1.push "redirect-gateway def1 bypass-dhcp": tells clients to send all traffic through the VPN. Remove it for a split tunnel, where only traffic for your network uses the VPN; then usepush "route 192.168.1.0 255.255.255.0"with your home network’s range instead.push "dhcp-option DNS 1.1.1.1": the DNS server clients should use. If you run Pi-hole, use its address to block ads on the go.user nobody,group nogroup: drop to an unprivileged user after starting, which limits the damage if the service is ever compromised. (On Fedora and Red Hat-based systems, the group isnobody.)
You don’t need to set a cipher: current OpenVPN versions negotiate AES-256-GCM or ChaCha20-Poly1305 automatically.
Step 5: Turn On IP Forwarding and NAT
For a full tunnel, the server must forward traffic from VPN clients to the internet and hide them behind its own address (NAT). First, turn on IP forwarding permanently:
echo 'net.ipv4.ip_forward=1' | sudo tee /etc/sysctl.d/99-openvpn.conf
sudo sysctl --system
Next, find the name of the server’s internet-facing network interface:
ip route show default
The name after dev, such as eth0 or ens3, is what you need. Then add the NAT rule, using that name:
sudo iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
This rule disappears when the server restarts. To keep it, install iptables-persistent (sudo apt install iptables-persistent) and save the rules when it asks, or save them later with sudo netfilter-persistent save.
Step 6: Open the Firewall and Start the Server
If you use UFW, allow the VPN port, then start OpenVPN and make it start at boot:
sudo ufw allow 1194/udp
sudo systemctl enable --now openvpn-server@server
sudo systemctl status openvpn-server@server
openvpn-server@server tells systemd to run /etc/openvpn/server/server.conf. If the status isn’t active (running), check the log with sudo journalctl -u openvpn-server@server.
On your router (for a home server) or in your cloud provider’s firewall, forward or allow UDP 1194 to the server.
Step 7: Create a Client Profile
A client needs four things: the CA certificate, its own certificate and key, and the tls-crypt key. The easiest way to deliver them is a single .ovpn file with everything inside. First, save this template as ~/client-template.txt, replacing vpn.example.com with your public IP address or domain name:
client
dev tun
proto udp
remote vpn.example.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
verb 3
Then save this script as ~/make-client.sh. It combines the template and the files for one device into a profile:
#!/bin/bash
# Usage: ./make-client.sh laptop
NAME=$1
cd ~/openvpn-ca
{
cat ~/client-template.txt
echo "<ca>"; cat pki/ca.crt; echo "</ca>"
echo "<cert>"; sed -n '/BEGIN CERTIFICATE/,/END CERTIFICATE/p' pki/issued/$NAME.crt; echo "</cert>"
echo "<key>"; cat pki/private/$NAME.key; echo "</key>"
echo "<tls-crypt>"; cat ta.key; echo "</tls-crypt>"
} > ~/$NAME.ovpn
Run it:
chmod +x ~/make-client.sh
~/make-client.sh laptop
This creates ~/laptop.ovpn. Treat this file like a password: anyone who has it can connect to your network. Copy it to the device securely, never by email or a public file share.
Step 8: Connect From Your Device
- Install OpenVPN Connect on Windows, macOS, iOS, or Android. (On Linux, run
sudo openvpn --config laptop.ovpn.) - Import the
.ovpnfile. - Connect.
To test it, connect from outside your network, such as a phone on mobile data. Look up your public IP address; with a full tunnel, it should now be your server’s address. You should also be able to reach devices on your home network.
When it works, the client’s log shows lines like these:
PUSH: Received control message: 'PUSH_REPLY,redirect-gateway def1 bypass-dhcp,dhcp-option DNS 1.1.1.1,route-gateway 10.8.0.1,topology subnet,ping 10,ping-restart 120,ifconfig 10.8.0.2 255.255.255.0,...'
Initialization Sequence Completed
Data Channel: cipher 'AES-256-GCM', peer-id: 0
Initialization Sequence Completed means the tunnel is up, and the client received its address, 10.8.0.2.
Easier Ways to Get an OpenVPN Server
Setting up OpenVPN by hand teaches you how it works, but there are simpler options:
- Your router or firewall. Many routers, and firewall platforms like pfSense and OPNsense, have a built-in OpenVPN server with a setup wizard.
- OpenVPN Access Server. A web interface for users, certificates, and client downloads, free for two simultaneous connections.
- Community install scripts. Popular open-source scripts automate the steps in this guide in a few minutes. Read any script before running it as root.
Keep Your VPN Secure
Revoke lost devices immediately. If a phone or laptop is lost, revoke its certificate:
cd ~/openvpn-ca ./easyrsa revoke laptop ./easyrsa gen-crl sudo cp pki/crl.pem /etc/openvpn/server/Then add
crl-verify crl.pemtoserver.conf(only once) and restart withsudo systemctl restart openvpn-server@server. The revoked device is refused with acertificate revokederror, while other devices keep working. Rungen-crlagain after every revocation, and at least every few months, because the list has an expiration date.Protect the CA key.
pki/private/ca.keycan create new certificates for your network. Keep it on a separate, offline computer if you can, with a strong passphrase.One certificate per device. Never share one profile among people or devices; it makes revoking access impossible without affecting everyone.
Keep OpenVPN and the server updated. Install security updates regularly.
Open only the VPN port. Don’t expose SSH or other services to the internet just because the VPN is there.
Consider MFA for business use. Access Server and plugins can add passwords and two-factor authentication on top of certificates.
Troubleshooting
| Problem | Likely cause | What to check |
|---|---|---|
TLS handshake failed or the client keeps retrying | UDP 1194 isn’t reaching the server | Router port forward, cloud firewall, UFW, and the address in remote |
| Connects, but no internet | Forwarding or NAT is missing | ip_forward is 1, the MASQUERADE rule uses the right interface |
| Connects, but websites don’t load by name | DNS isn’t working through the tunnel | The dhcp-option DNS address, and that clients can reach it |
certificate revoked | The device’s certificate was revoked | Create a new certificate and profile for that device |
| Certificate errors on a device with the wrong date | Certificates depend on correct time | Fix the device’s date and time |
| Works at home but not from a hotel or office | UDP is blocked there | Run a second server instance on proto tcp and port 443 |
Frequently Asked Questions
Is OpenVPN free?
Yes. OpenVPN Community Edition and the OpenVPN Connect app are free and open source. OpenVPN Inc. also sells Access Server and CloudConnexa, which have free tiers.
Is OpenVPN secure?
Yes, when configured well. It uses TLS with certificates and modern encryption, and it has been widely audited and used for more than two decades. Most real-world problems come from configuration: weak CA protection, shared profiles, unrevoked lost devices, or outdated software.
Should I use OpenVPN or WireGuard?
WireGuard is faster and simpler to configure. OpenVPN is more flexible: it can run over TCP to get through strict firewalls, supports certificate revocation and many authentication plugins, and is supported by a huge range of devices and services. For a new personal setup, WireGuard or Tailscale is often easier; OpenVPN is a strong choice when you need its flexibility.
Does a VPN make me anonymous?
No. A VPN moves trust from your local network and internet provider to the VPN server. With your own server, your traffic exits from your server’s address, which is tied to you. It protects you on untrusted networks, but it doesn’t hide your identity from the sites you sign in to.
What’s the difference between tun and tap?
tun creates a routed connection for IP traffic, which is what almost everyone needs. tap bridges full Ethernet frames, used only for special cases like non-IP protocols or putting clients on the same network segment.
Conclusion
OpenVPN is a proven, flexible way to build your own VPN: certificates control who can connect, TLS and modern ciphers protect the traffic, and it runs almost everywhere, even through restrictive firewalls over TCP 443. Setting up a server takes a few steps: create a CA and certificates with Easy-RSA, write a short server configuration, turn on forwarding and NAT, and hand each device its own .ovpn profile. Keep one certificate per device, revoke what’s lost, protect your CA key, and keep everything updated, and you’ll have secure access to your network from anywhere.
