ThisCalculator

Everyday

OpenVPN on TCP Port 80 with a Domain Name

Updated · Standard formula, shown below

This guide walks you through configuring an OpenVPN server to listen on TCP port 80 and connecting to it using a domain name instead of a raw IP address. This setup is useful when you’re behind a restrictive firewall that only allows web traffic, or when you want a cleaner, more memorable connection endpoint. You’ll need a Linux server (Ubuntu/Debbian assumed), a domain name pointing to that server’s public IP, and root access.

What You’ll Need

  • A Linux server (Ubuntu 20.04+ or Debian 11+) with root or sudo access
  • A domain name (e.g., vpn.example.com) with an A record pointing to your server’s public IP
  • OpenVPN and Easy-RSA installed (we’ll cover installation)
  • Port 80 must be free on the server (stop any web server like Apache/Nginx if running)
  • OpenVPN client software on the device you’ll connect from

Step-by-Step

  1. Update your system and install OpenVPN and Easy-RSA
    Run sudo apt update && sudo apt upgrade -y, then sudo apt install openvpn easy-rsa -y.
  2. Set up the Easy-RSA directory
    Copy the Easy-RSA scripts to a working directory: sudo mkdir /etc/openvpn/easy-rsa && sudo cp -r /usr/share/easy-rsa/* /etc/openvpn/easy-rsa/. Then cd /etc/openvpn/easy-rsa.
  3. Initialize the PKI and build the CA
    Run sudo ./easyrsa init-pki, then sudo ./easyrsa build-ca nopass. You’ll be asked for a Common Name (e.g., “MyVPN CA”). This creates the Certificate Authority.
  4. Generate the server certificate and key
    Run sudo ./easyrsa gen-req server nopass (accept the default CN or change it), then sudo ./easyrsa sign-req server server. Type “yes” when prompted.
  5. Generate Diffie-Hellman parameters
    Run sudo ./easyrsa gen-dh. This may take a few minutes.
  6. Generate a client certificate
    For each client, run sudo ./easyrsa gen-req client1 nopass and sudo ./easyrsa sign-req client client1. Repeat for each device.
  7. Copy the necessary files to the OpenVPN directory
    Run sudo cp pki/ca.crt pki/issued/server.crt pki/private/server.key pki/dh.pem /etc/openvpn/
  8. Create the OpenVPN server configuration file
    Create /etc/openvpn/server.conf with the following content (adjust paths if needed):

    port 80
    proto tcp
    dev tun
    ca /etc/openvpn/ca.crt
    cert /etc/openvpn/server.crt
    key /etc/openvpn/server.key
    dh /etc/openvpn/dh.pem
    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
    tls-server
    tls-version-min 1.2
    user nobody
    group nogroup
    persist-key
    persist-tun
    status openvpn-status.log
    verb 3
  9. Enable IP forwarding
    Edit /etc/sysctl.conf and uncomment or add net.ipv4.ip_forward=1. Then run sudo sysctl -p.
  10. Set up NAT (if you want clients to access the internet)
    Run sudo iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE (replace eth0 with your internet-facing interface). To make it persistent, install iptables-persistent and save rules.
  11. Start and enable OpenVPN
    Run sudo systemctl start openvpn@server and sudo systemctl enable openvpn@server. Check status with sudo systemctl status openvpn@server.
  12. Create client configuration files
    For each client, create a .ovpn file with:

    client
    dev tun
    proto tcp
    remote yourdomain.com 80
    resolv-retry infinite
    nobind
    persist-key
    persist-tun
    ca [inline]
    cert [inline]
    key [inline]
    tls-client
    tls-version-min 1.2
    cipher AES-256-CBC
    verb 3
    <ca>
    (contents of ca.crt)
    </ca>
    <cert>
    (contents of client1.crt)
    </cert>
    <key>
    (contents of client1.key)
    </key>

    Replace yourdomain.com with your actual domain. Inline the certificate contents between the tags.

  13. Test the connection
    Import the .ovpn file into your OpenVPN client and connect. You should see a successful connection and get an IP in the 10.8.0.0/24 range.

Common Mistakes

  • Port 80 already in use – If Apache or Nginx is running, OpenVPN fails to bind. Stop the web server or change its port.
  • Wrong protocol mismatch – The client must also use proto tcp. If your client is set to UDP, it won’t connect.
  • Firewall blocking port 80 – Ensure your server’s firewall (ufw/iptables) allows TCP port 80. Run sudo ufw allow 80/tcp if using ufw.
  • Incorrect file permissions – The server key must be readable only by root. If permissions are too open, OpenVPN may refuse to start.
  • Domain not resolving – Verify the A record points to the server’s IP with dig yourdomain.com or nslookup.

Tips

  • Use a subdomain like vpn.example.com to keep things organized.
  • Consider using a free dynamic DNS service if your IP changes often, but that’s outside this guide.
  • Add tls-crypt or tls-auth for extra security (requires extra key generation).
  • Use auth SHA256 in both server and client configs for better integrity.
  • Keep your CA private key offline after generating certificates to prevent compromise.

Troubleshooting

  • Connection times out – Check if port 80 is reachable from outside: telnet yourdomain.com 80 from a remote machine. If it fails, check firewall and that OpenVPN is listening (sudo netstat -tulpn | grep :80).
  • Client gets “TLS Error: TLS key negotiation failed” – Usually means a mismatch in certificates or the client/server configs. Verify the CA, cert, and key files are correctly referenced and match.
  • Client connects but no internet – Check IP forwarding (sysctl net.ipv4.ip_forward should return 1) and NAT rule. Also ensure the client’s DNS is set correctly.
  • Server won’t start – Check logs: sudo journalctl -u openvpn@server. Common causes: missing files, wrong paths, or permission issues.
  • Port 80 is blocked by ISP – Some ISPs block port 80 for non-web traffic. If so, you may need to use a different port (e.g., 443) or a port forwarder.

Frequently Asked Questions

Why use TCP port 80 instead of the default UDP 1194?

Port 80 is often allowed through firewalls because web traffic uses it. Using TCP ensures the connection looks like regular HTTP, bypassing restrictive networks that block other ports.

Can I use port 80 if I already have a web server?

No, only one service can bind to port 80 at a time. You’d need to either stop the web server, move it to another port, or use a reverse proxy that can multiplex (but that’s more complex).

Do I need a static IP for my domain?

Yes, the domain must resolve to your server’s current IP. If your IP changes, update the DNS record or use a dynamic DNS service.

Is this setup secure?

Yes, with proper certificates and strong ciphers, it’s secure. However, using port 80 may attract more scans; consider adding tls-crypt to obscure the handshake.

Can I use this guide for Windows or macOS clients?

Yes, the client .ovpn file works with OpenVPN GUI on Windows, Tunnelblick on macOS, and the official OpenVPN Connect app on mobile.

How do I add more clients later?

Generate a new client cert/key on the server using Easy-RSA, then create a new .ovpn file with those credentials. No server restart is needed.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.