In several previous articles I described how to install an OpenVPN server on a Raspberry Pi (natively, inside OpenMediaVault and inside a Docker container).
In this article I will describe how to assign a specific IP address to an OpenVPN client.
To do this, connect to your OpenVPN server via SSH and, inside the /etc/openvpn folder, create a folder called ccd.
ccd stands for client config directory and will contain the configuration for the client to which you want to assign a specific IP address.
First, edit the /etc/openvpn/server.conf file with the following command:
sudo nano /etc/openvpn/server.conf
and add the following line
client-config-dir ccd
Once you have pasted the text, close the file by pressing CTRL+X, then type Y (or S, depending on your system language) and finally press ENTER to confirm.
Now that we have told the OpenVPN server about this folder, we simply need to create a configuration file in the /etc/openvpn/ccd folder for each client to which we want to assign a specific IP address
The name of the file must match the CN (common name) of the associated client exactly
sudo nano /etc/openvpn/ccd/[CN_client_name]
for example:
sudo nano /etc/openvpn/ccd/laptop_jaq
and enter the following text in it:
ifconfig-push [IP] [Subnet Mask]
For example:
ifconfig-push 10.9.0.200 255.255.255.0
Again, once you have entered the text, close the file by pressing CTRL+X, then type Y (or S, depending on your system language) and finally press ENTER to confirm.
Once this is done, restart the OpenVPN service with the following command:
sudo /etc/init.d/openvpn restart
and, as soon as the service is back up, connect the client to check that everything works.
Enjoy!
