OpenVPN

1. Server
1.1. Installation
1.2. Setup
To set up your own CA, and generate certificates and keys for an OpenVPN server with multiple clients, first copy the easy-rsa directory to /etc/openvpn. This will ensure that any changes to the scripts will not be lost when the package is updated.
As root in /etc/openvpn/easy-rsa:
The PEM passphrase set when creating the CA will be asked for every time you need to encrypt the output of a command (such as a private key).
Generate a key pair for the server:
Diffie Hellman parameters must be generated for the OpenVPN server. The following command will place them in pki/dh.pem:
And finally, create a certificate for the server:
All certificates and keys have been generated in subdirectories. Common practice is to copy them to /etc/openvpn/:
Create the TLS Authentication (TA) key in etc/openvpn:
Edit /etc/sysctl.conf and uncomment the following line to enable IP forwarding:
Reload sysctl:
[Optional] Copy the example server.conf file to /etc/openvpn/:
Edit the /etc/openvpn/server.conf according to your prefences and run OpenVPN client as follows:
1.3. Client key generation
To create the client certificate, enter the following in a terminal as a root user in folder /etc/openvpn/:
client.conf
Copy the following files to the client in the same folder of <client_name>.conf file using a secure method:
pki/ca.crtpki/issued/<client_name>.crtpki/private/<client_name>.keyta.key
client.conf
Copy the content of the following files in the <client_name>.ovpn file:
pki/ca.crtpki/issued/<client_name>.crtpki/private/<client_name>.keyta.key
1.4. Client IP assignment
Create the following folder on the server:
Define the IP address of client with name client_name by creating the file /etc/openvpn/ccd/client_name with this content:
Where 10.8.1.2 is the IP address that will be assigned to the client client_name in the VPN subnet with subnet mask 255.255.255.0.
2. Client
2.1 Installation
2.2. Setup
[Optional] Copy the example client.conf file to /etc/openvpn/:
Then you need to specify ca.crt
Edit /etc/openvpn/client.conf according to your prefences and run OpenVPN client as follows:
3. Common setup scenarios
3.1. Split-tunnel
/etc/openvpn/server.conf:
<client_name>.ovpn:
Full-tunnel
After enabling full tunnel routing, the VPN server needs to be able to masquerade the VPN client's IP addresses when they access the internet. Setup the NAT on the server via iptables:
/etc/openvpn/server.conf:
<client_name>.ovpn:
Last updated