Run Multiple OpenVPN Servers for Many Clients
This guide explains how to run multiple OpenVPN servers on a single machine (or across several) to handle many clients, whether you need separate networks, different authentication methods, or want to scale beyond what one server can handle. You’ll learn how to configure each instance with its own port, config file, and IP range, and how to manage them cleanly. You’ll need root access to a Linux server (Ubuntu/Debbian used here) and basic command-line comfort.
What You’ll Need
- A Linux server (Ubuntu 20.04/22.04 or Debian 10/11) with root access
- OpenVPN and Easy-RSA installed (
apt install openvpn easy-rsa) - At least one public IP address (more if you want each server on its own IP)
- Basic knowledge of the command line and text editing (nano or vim)
Step-by-Step
- Plan your servers. Decide how many OpenVPN servers you need and what each will be used for. For example, server1 for remote workers, server2 for site-to-site, server3 for guests. Each server will need a unique port (e.g., 1194, 1195, 1196) and its own subnet (e.g., 10.8.0.0/24, 10.9.0.0/24, 10.10.0.0/24).
- Set up the CA and certificates. If you haven’t already, initialize Easy-RSA and create a Certificate Authority. This CA will issue certificates for all servers and clients. Run
make-cadir ~/easy-rsa, then editvarsto set your organization details. Then run./easyrsa init-pki,./easyrsa build-ca, and create a server certificate for each server:./easyrsa gen-req server1 nopass,./easyrsa sign-req server server1, repeat for server2, etc. - Create server directories and config files. For each server, create a directory under
/etc/openvpn(e.g.,/etc/openvpn/server1,/etc/openvpn/server2). Copy the relevant certificates and keys into each directory. Then create a config file (e.g.,server1.conf) inside that directory. A minimal config looks like:port 1194 proto udp dev tun ca ca.crt cert server1.crt key server1.key dh dh.pem server 10.8.0.0 255.255.255.0 push "redirect-gateway def1" push "dhcp-option DNS 8.8.8.8" keepalive 10 120 cipher AES-256-GCM auth SHA256 user nobody group nogroup persist-key persist-tun status server1-status.log log-append server1.log verb 3
Adjust the port, subnet, and file names for each server.
- Generate DH parameters (or use a shared one). For each server, you need a dh.pem file. You can generate one per server (
openssl dhparam -out dh.pem 2048) or copy the same one to all servers. Generating once and copying is faster. - Enable IP forwarding. Edit
/etc/sysctl.confand uncomment or addnet.ipv4.ip_forward=1. Then runsysctl -pto apply. - Set up NAT (if clients need internet). For each server’s subnet, add an iptables rule. For example, if your server’s external interface is eth0:
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE iptables -t nat -A POSTROUTING -s 10.9.0.0/24 -o eth0 -j MASQUERADE
To make these persistent, install
iptables-persistentor add them to a startup script. - Start each server. With systemd, you can start each server by referencing its config file name. For example,
systemctl start openvpn@server1andsystemctl enable openvpn@server1. Repeat for server2, server3, etc. Note: the config file must be in/etc/openvpnor/etc/openvpn/serverdepending on your distribution. - Create client certificates and configs. For each client, generate a certificate and key:
./easyrsa gen-req client1 nopass,./easyrsa sign-req client client1. Then create a client config file that points to the correct server IP and port. Example:client dev tun proto udp remote your_server_ip 1194 resolv-retry infinite nobind persist-key persist-tun ca ca.crt cert client1.crt key client1.key cipher AES-256-GCM auth SHA256 verb 3
Send the client the .ovpn file (which includes the ca, cert, and key inline) or provide the files separately.
- Test each server. Connect a client to each server and verify that they get the correct IP and can ping the server’s internal IP (e.g., 10.8.0.1). Also test internet access if you enabled NAT.
- Scale to many clients. Each OpenVPN server can handle hundreds of clients, but if you need more, you can add more servers on different ports or IPs. Distribute client configs across servers to balance the load. You can also use a load balancer or DNS round-robin, but that requires more advanced setup.
Common Mistakes
- Port conflicts: If you forget to change the port in the config, the second server won’t start because the port is already in use.
- Subnet overlap: Using the same subnet (e.g., 10.8.0.0/24) for two servers will cause routing conflicts. Always use unique subnets.
- Certificate mismatch: Using the wrong server certificate (e.g., server2.crt on server1) will cause TLS errors. Double-check the file names in each config.
- Missing dh.pem: Without dh.pem, the server won’t start. Ensure it’s present in each server directory.
- Firewall blocking: If your firewall (ufw, iptables) isn’t configured to allow the new ports, clients can’t connect. Open the ports (e.g., 1194/udp, 1195/udp, etc.).
- Not enabling IP forwarding: Clients can connect but can’t route traffic to the internet or other networks.
Tips
- Use a different CA for each server if you want to isolate security, but for most cases a single CA is fine and simpler.
- Use
tls-cryptortls-authto add an extra layer of security against port scanning and DoS. - Monitor each server’s status log to see connected clients and troubleshoot issues.
- Consider using a configuration management tool (like Ansible) to deploy multiple servers consistently.
- For high availability, you can run servers on different machines and use DNS round-robin or a load balancer, but that’s beyond this guide.
- Use
--duplicate-cnonly if you need multiple clients with the same certificate (not recommended for security).
Troubleshooting
Server won’t start: Check the log file (e.g., /var/log/openvpn/server1.log) for errors. Common issues: missing files, wrong permissions, or port already in use. Use journalctl -u openvpn@server1 if using systemd.
Client can’t connect: Verify the client config points to the correct IP and port. Check the server log for connection attempts. If you see TLS errors, the certificates might be mismatched or the CA is wrong.
Client connects but no internet: Ensure IP forwarding is enabled and iptables NAT rules are in place. Test with ping 8.8.8.8 from the client. If that works but DNS fails, check the DNS push settings.
Multiple servers interfering: If you accidentally used the same subnet, clients from one server might get IPs that conflict. Check the routing table on the server with ip route and adjust subnets.
Slow performance: If you have many clients on one server, consider adding more servers or upgrading hardware. Also check CPU and bandwidth usage.
Frequently Asked Questions
Can I run multiple OpenVPN servers on the same machine?
Yes, as long as each uses a different port and a different subnet. The systemd service openvpn@config makes it easy to run multiple instances.
How many clients can a single OpenVPN server handle?
It depends on hardware and network, but a typical server can handle several hundred concurrent clients. For more, you need multiple servers.
Do I need a separate IP address for each server?
No, you can use the same IP with different ports. But if you want to load balance or separate traffic by IP, you’ll need additional IPs.
Can I use UDP and TCP for different servers?
Yes, you can set one server to use UDP and another TCP, as long as the ports don’t conflict. This can help with firewalls that block one protocol.
How do I revoke a client certificate?
Use Easy-RSA: ./easyrsa revoke client1 and then ./easyrsa gen-crl. On the server, add crl-verify crl.pem to the config and restart.
Can I use the same certificate for multiple clients?
Technically yes, but it’s not recommended because you can’t revoke one without revoking all. Generate unique certificates for each client.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.