Step-by-step guide to install and configure an OpenVPN server on Ubuntu, followed by instructions for connecting to it using a mobile client.
Step 1: Update Your System
Before installing OpenVPN, ensure your system is up to date.
Step 2: Install OpenVPN and Easy-RSA
Install OpenVPN and the Easy-RSA package, which will be used to set up a Certificate Authority (CA).
Step 3: Set Up the Easy-RSA Directory
Create and configure the Easy-RSA directory.
Step 4: Configure Variables
Edit the vars
file to set custom values for your certificates.
Modify the following lines as needed:
Save and exit the editor (Ctrl+O
, Enter
, then Ctrl+X
).
Step 5: Build the Certificate Authority (CA)
Clean up the directory and build the CA.
When prompted, set a password for the CA and confirm it.
Step 6: Generate Server and Client Certificates
Generate the server certificate and key.
Generate client certificates for the first client (e.g., client1
).
Step 7: Generate Diffie-Hellman Parameters and TLS Key
Generate Diffie-Hellman parameters and a static key for encryption.
Step 8: Configure the OpenVPN Server
Copy the generated certificates, keys, and other necessary files to the OpenVPN directory.
Create a server configuration file.
Add the following configuration:
Save and exit.
Step 9: Start and Enable the OpenVPN Service
Start the OpenVPN server and enable it to start on boot.
Step 10: Configure Firewall Rules
Allow OpenVPN traffic through the firewall.
Enable IP forwarding by editing the following file:
Uncomment or add the following line:
Apply the changes:
Step 11: Generate Client Configuration
Create a client configuration file:
Add the following content:
Replace YOUR_SERVER_IP
with your server's public IP address.
Export the client configuration to your client device. For example:
Step 12: Connect from a Mobile Client
- Download the OpenVPN app on your mobile device.
- Transfer the
client1.ovpn
file to your mobile. - Open the OpenVPN app, import the configuration file, and connect.