Static IPs for OpenVPN Clients

You can optionally make it so that the OpenVPN clients get the same private VPN IP addresses every time they connect.

Get into the OpenVPN server and run the following commands:

echo 'client-config-dir /etc/openvpn/ccd' >> /etc/openvpn/server/server.conf

This tells the server to look for extra configuration for its clients in /etc/openvpn/ccd dir. Your server’s server.conf location file might be different from /etc/openvpn/server/server.conf. Make sure to double-check this and correct the command if needed.

mkdir -p /etc/openvpn/ccd

Create the client-config-dir we referenced earlier.

echo 'ifconfig-push 10.8.0.10 255.255.255.0' >> /etc/openvpn/ccd/client1

This tells the server to give the 10.8.0.10 IP address to the client named client1 every time it connects. The IP address has to be from the VPN addresses pool. You can look up the IP address pool or the VPN network mask in other words in the server’s config file at the line that reads server 10.8.0.0 255.255.255.0 (example). Make sure not to take the very first IP address in the range, e.g. 10.8.0.0, as it’s usually taken by the server itself.

systemctl restart [email protected]

Finish up by restarting the server.

Repeat the 3rd command to give static IPs to more clients.