For the complete documentation index, see llms.txt. This page is also available as Markdown.

OpenVPN server on Ubuntu 18.06

Install openvpn server on Ubuntu 18.06

Setup server

Leverage an AWS instance

Leverage an instance with:

  • "Source/Destination Check" disabled.

  • Firewall open on port 1194/UDP.

Configure IP forward

Run:

nano /etc/sysctl.conf

Enable net.ipv4.ip_forward:

net.ipv4.ip_forward=1

Apply changes:

sysctl -p

If you are using ufw...

Get your default network card:

ip route | grep default

Output example:

Edit ufw config:

Add the block START OPENVPN RULES and END OPENVPN RULES:

Edit ufw default config:

Allow forward:

Allow openvpn and SSH:

Install Openvpn

Run:

Download EasyRSA:

Copy and edit vars:

Uncomment and change the following config:

Initiate the public key:

Build CA certificate. Keep the default Common Name and hit enter:

Create a private key for the server and a certificate request:

Copy the server key to the /etc/openvpn/ directory:

Sign the request. Input yes when prompted:

Sign the request. Input yes when prompted:

Copy certificates to openvpn dir:

Create a strong Diffie-Hellman key to use during key exchange (may take a few minutes to complete):

Generate an HMAC signature to strengthen the server's TLS integrity verification capabilities:

Copy the files to openvpn dir:

Configuring the OpenVPN Service

Copy sample config:

Edit server config:

Double check tls-auth and add key-direction:

Double check cipher and add auth:

Change dh:

Enable user and group:

Enable client-to-client:

Start and enable service:

Setup client config

Run:

Config remote server:

Double check proto:

Enable user and group:

Comment out certificates (they are provided in the .ovpn file):

Double check cipher and add auth:

Add these lines in the end of the file. The last ones are commented out (only need to enable them for Linux clients that ship with an /etc/openvpn/update-resolv-conf file):

Create a script to compile the base config:

Add:

Set permissions:

Add client certificate

Generate certificate:

References

https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-ubuntu-18-04

https://hackernoon.com/using-a-vpn-server-to-connect-to-your-aws-vpc-for-just-the-cost-of-an-ec2-nano-instance-3c81269c71c2

Revoke certificate

Run EasyRsa revoke command. Type yes when prompted:

Create a certificate revocation list (CRL):

Copy the CRL to the server config folder:

Edit server config:

Add the following line to the end of the file:

Restart server:

References

https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-ubuntu-18-04

Multi instances

Copy your current server config:

Edit the new file:

Change the following config:

Start the server:

References

https://www.hugeserver.com/kb/openvpn-multiple-ports/

Fixed IP for clients

Edit servers config:

Uncomment the following line:

Create the dir:

Create a file with same CN name used in the certificate:

Define the static IP:

Restart server:

References

https://www.itsfullofstars.de/2018/09/openvpn-assign-static-ip-to-client/

https://serverfault.com/questions/826560/how-to-set-a-static-ip-client-side-in-openvpn

Restrict Client-to-client

Edit server config:

Make sure the option client-to-client is disabled:

Add the following line in the end of the file to route all traffic to the VPN server:

Configure iptables:

References

https://backreference.org/2010/05/02/controlling-client-to-client-connections-in-openvpn/

Debug

Check service:

Monitor packets on interface tun0:

Monitor ping on interface vpn-cluster with buffer size 512 (it is not set, the “packets dropped by kernel” will always be zero):

Check open port:

Last updated