Setting up an OpenVPN server provides a robust solution for securing your internet connection and accessing network resources remotely. This guide walks through the essential steps to deploy a reliable and secure VPN server on a Linux-based system.
Preparing Your Server Environment
Before installing OpenVPN, ensure your server has a static public IP address and updated system packages. A clean installation of Ubuntu 20.04 or 22.04 LTS is recommended for compatibility and ease of configuration.
Installing OpenVPN and Easy-RSA
Install the necessary packages using the package manager. The following commands install OpenVPN, Easy-RSA for certificate management, and additional utilities required for the setup.
Update the package index: sudo apt update
Install OpenVPN and Easy-RSA: sudo apt install openvpn easy-rsa
Configuring the Certificate Authority
Establishing a trusted certificate authority is critical for client authentication. Easy-RSA simplifies the process of creating and managing the required cryptographic keys and certificates.
Setting Up the PKI
Copy the Easy-RSA template directory to a new location and edit the vars file to define your certificate parameters. This includes setting the country, organization, and common names for the server and clients.
Initialize the Public Key Infrastructure (PKI): ./easyrsa init-pki
Build the Certificate Authority: ./easyrsa build-ca
Generating Server and Client Certificates
With the CA established, you can generate the server certificate and key, as well as individual certificates for each connecting client. This process ensures that only authorized devices can join the VPN network.
Configuring the OpenVPN Server
The server configuration file defines network parameters, security protocols, and certificate paths. A well-structured configuration ensures stability and compatibility across different client devices.
Copy the sample configuration file: gunzip -c /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz > /etc/openvpn/server.conf
Edit server.conf to point to your generated certificates and keys
Set the push "redirect-gateway def1"` directive to route all client traffic through the VPN
Starting the VPN Service
Enable and start the OpenVPN service to apply your configuration. Verify that the service is active and listening on the correct port to accept incoming connections.