Setting up an open source VPN gives you secure, private internet access without relying on commercial services, using freely available software you can audit and modify yourself.

What You'll Need

  • A server (physical machine, VPS, or cloud instance) running a Linux distribution like Ubuntu 22.04 LTS or Debian 12
  • Root or sudo access to the server
  • A domain name pointing to your server’s public IP (optional but recommended for easier client setup)
  • A client device (Windows, macOS, Linux, iOS, or Android) to connect from
  • Basic familiarity with the Linux command line

Step-by-Step

  1. Update your server’s package list and install dependencies: run sudo apt update && sudo apt install -y openvpn easy-rsa on Ubuntu/Debian. On CentOS/RHEL, use sudo yum install -y openvpn easy-rsa or dnf for newer versions.
  2. Set up the Easy-RSA PKI directory: make-cadir ~/openvpn-ca, then cd ~/openvpn-ca. Edit the vars file to set your KEY_COUNTRY, KEY_PROVINCE, KEY_CITY, KEY_ORG, and KEY_EMAIL values.
  3. Load the variables and build the CA: source vars followed by ./clean-all and ./build-ca. Press Enter to accept defaults or enter your details when prompted.
  4. Generate the server certificate and key: ./build-key-server server. Again, accept defaults or enter a challenge password if desired (leave blank for no password).
  5. Generate Diffie-Hellman parameters: ./build-dh. This may take a few minutes.
  6. Generate an HMAC signature to strengthen the server’s TLS integrity verification: openvpn --genkey --secret ta.key.
  7. Copy the generated files to the OpenVPN directory: sudo cp ~/openvpn-ca/keys/{ca.crt,server.crt,server.key,ta.key,dh2048.pem} /etc/openvpn/.
  8. Create the server configuration file: sudo nano /etc/openvpn/server.conf and add: port 1194 proto udp dev tun ca ca.crt cert server.crt key server.key dh dh2048.pem tls-auth ta.key 0 topology subnet server 10.8.0.0 255.255.255.0 ifconfig-pool-persist ipp.txt push "redirect-gateway def1 bypass-dhcp" push "dhcp-option DNS 8.8.8.8" push "dhcp-option DNS 8.8.4.4" keepalive 10 120 cipher AES-256-CBC auth SHA256 user nobody group nogroup persist-key persist-tun status openvpn-status.log verb 3 Save and exit (Ctrl+O, Enter, Ctrl+X in nano).
  9. Enable IP forwarding: edit /etc/sysctl.conf and uncomment or add net.ipv4.ip_forward=1. Apply changes with sudo sysctl -p.
  10. Configure the firewall (using UFW on Ubuntu): sudo ufw allow 1194/udp and sudo ufw allow OpenSSH. Then enable forwarding by editing /etc/ufw/before.rules and adding after the *filter line: *nat :POSTROUTING ACCEPT [0:0] -A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE COMMIT Replace eth0 with your server’s public interface (find it with ip route get 8.8.8.8).
  11. Disable UFW temporarily to avoid conflicts during setup: sudo ufw disable, then re-enable after rules are in place: sudo ufw enable.
  12. Start and enable the OpenVPN service: sudo systemctl start openvpn@server and sudo systemctl enable openvpn@server. Check status with sudo systemctl status openvpn@server.
  13. Generate client certificates: cd ~/openvpn-ca, source vars, then ./build-key client1 (replace client1 with a name for your device). Leave challenge password blank unless required.
  14. Create the client configuration file: mkdir ~/client-configs/files, cp ~/openvpn-ca/keys/{ca.crt,client1.crt,client1.key} ~/client-configs/files/, and cp /etc/openvpn/ta.key ~/client-configs/files/.
  15. Create a base client config: nano ~/client-configs/base.conf with: client dev tun proto udp remote YOUR_SERVER_IP 1194 resolv-retry infinite nobind user nobody group nogroup persist-key persist-tun remote-cert-tls server tls-auth ta.key 1 cipher AES-256-CBC auth SHA256 verb 3 Replace YOUR_SERVER_IP with your server’s public IP or domain name.
  16. Make a script to generate unified .ovpn files: nano ~/client-configs/make_config.sh with: #!/bin/bash KEY_DIR=~/openvpn-ca/keys OUTPUT_DIR=~/client-configs/files BASE_CONFIG=~/client-configs/base.conf cat ${BASE_CONFIG} \ <(echo -e '') \ ${KEY_DIR}/ca.crt \ <(echo -e '\n') \ ${KEY_DIR}/${1}.crt \ <(echo -e '\n') \ ${KEY_DIR}/${1}.key \ <(echo -e '\n') \ ${KEY_DIR}/ta.key \ <(echo -e '') \ > ${OUTPUT_DIR}/${1}.ovpn Save, then make executable: chmod +x ~/client-configs/make_config.sh.
  17. Generate the client .ovpn file: cd ~/client-configs && ./make_config.sh client1. The file client1.ovpn will be in ~/client-configs/files/.
  18. Transfer the .ovpn file to your client device (via email, USB, or secure copy). Install an OpenVPN client app (OpenVPN Connect for iOS/Android, Tunnelblick for macOS, or official OpenVPN client for Windows/Linux). Import the .ovpn file and connect.
  19. Verify the connection: check your public IP (e.g., via curl ifconfig.me) — it should now match your server’s IP. Also confirm DNS leak protection by visiting dnsleaktest.com.

Common Mistakes

  • Forgetting to enable IP forwarding in sysctl, which prevents traffic from routing through the VPN.
  • Using the wrong network interface in the POSTROUTING rule (e.g., eth0 when the server uses ens5), causing NAT to fail.
  • Not opening UDP port 1194 in the firewall, leading to connection timeouts.
  • Using TCP instead of UDP in client/server configs when UDP is intended, causing poor performance or failed handshakes.
  • Neglecting to set correct file permissions on keys and configs, leading to permission denied errors when starting the service.
  • Using outdated Easy-RSA versions or skipping the source vars step, resulting in failed certificate generation.

Tips

  • Use a domain name with Dynamic DNS (like DuckDNS or No-IP) if your server has a changing public IP, so clients don’t need reconfiguration.
  • Enable TLS-auth (as shown) to defend against DoS attacks and port scanning — it adds a shared secret HMAC key.
  • Consider using TCP port 443 instead of UDP 1194 if you need to bypass restrictive firewalls (e.g., in censored networks), though performance may suffer.
  • Regularly update your server and OpenVPN to patch security vulnerabilities — enable automatic security updates if available.
  • Monitor the OpenVPN log (/var/log/openvpn.log or via journalctl) for connection issues or suspicious activity.
  • For mobile clients, enable compression and keepalive settings to maintain connections on unstable networks.

Troubleshooting

  1. If the client cannot connect, first check server status: sudo systemctl status openvpn@server. Look for errors in the log.
  2. Verify the server is listening: sudo netstat -tulnp | grep 1194 or ss -tulnp | grep 1194. If not, the service failed to start.
  3. Check firewall rules: sudo ufw status or sudo iptables -L -n -v to ensure UDP 1194 is allowed and NAT is active.
  4. On the client, try connecting with increased verbosity: add verb 4 to the .ovpn file or use the app’s log feature to see handshake details.
  5. If you see TLS handshake failures, confirm the ta.key is correctly included and that the server and client both have the same key.
  6. If connected but no internet access, verify IP forwarding (cat /proc/sys/net/ipv4/ip_forward should return 1) and that the POSTROUTING rule matches your outgoing interface.
  7. For DNS leaks, ensure the push "dhcp-option DNS" lines are in the server config and that the client accepts pushed options (most do by default).
  8. If the server log shows Auth Username/Password verification failed for user, you may have accidentally enabled auth-user-pass without setting it up — remove it from config if not using certificates.
  9. As a last resort, temporarily disable the firewall (sudo ufw disable) to test if it’s blocking traffic — re-enable immediately after testing.

Frequently Asked Questions

Is OpenVPN still secure in 2024?

Yes, OpenVPN remains secure when properly configured with strong encryption (AES-256, SHA256) and up-to-date versions. It has undergone extensive audits and is widely trusted.

Can I use OpenVPN on a Raspberry Pi?

Yes, OpenVPN runs well on Raspberry Pi OS (32-bit or 64-bit). Performance is adequate for light to moderate use; consider WireGuard for higher throughput on Pi 4 or later.

Do I need a static IP for my VPN server?

Not strictly — you can use a dynamic DNS service to map a changing IP to a hostname, which clients can use in their .ovpn files.

Is it safe to use public Wi-Fi with my own OpenVPN server?

Yes, connecting to your own VPN on public Wi-Fi encrypts your traffic between your device and the server, protecting it from local network eavesdropping.

How many clients can connect simultaneously?

The server configuration supports multiple concurrent connections; the limit is mainly bandwidth and server resources. Each client needs a unique certificate.

Should I use UDP or TCP for OpenVPN?

UDP is preferred for better performance and lower latency. Use TCP only if UDP is blocked (e.g., by strict firewalls) and you need to tunnel over port 443 to mimic HTTPS traffic.