When using OpenVPN to organize a private virtual network, it is often necessary for clients to have static IP addresses. This is quite convenient in order to quickly get access to the desired device. This can be added in two ways. With the help of the ipp.txt file or the ccd directory. In this article we will consider both ways how to make a static IP of the OpenVPN client.
The name ipp stands for ifconfig pool persist. To make IP addresses from this file work you need to add this line to the server configuration file:
$ sudo vi /etc/openvpn/server.conf
$ ifconfig-pool-persist ipp.txt
Then the required IP addresses can be added in the file /etc/openvpn/ipp.txt. The syntax of this file is as follows:
user_name, ip_address
Note that the IP address must be within the range of addresses issued by the OpenVPN server. To see the range you can find the server line in the server configuration file:
server 10.8.0.0 255.255.255.0
IP addresses from 10.8.0.1 to 10.8.0.255 are used here. The first address is assigned to the server itself. You can see what address is assigned to the server now and give addresses to clients from the same subnet. You can find out the address of the server by looking at the IP address of the tun0 network interface:
$ ip -br a | grep tun
If you want the IP address 10.8.0.112 to be used for the raspberrypi client, add this line to the ipp.txt file:
$ sudo vi /etc/openvpn/ipp.txt
raspberrypi,10.8.0.11
To apply the changes you need to restart the OpenVPN server:
$ sudo systemctl restart openvpn@server
The ipp.txt option is easy. If more customizations are needed, you can use ccd. This stands for client config dir. With this feature you can set a separate configuration for each client, including IP address. To make it work you need to add this line to the configuration file:
$ sudo vi /etc/openvpn/server.conf
client-config-dir /etc/openvpn/ccd
In the /etc/openvpn/ccd
folder you can create configuration files with the name of the client and write there the settings that will be applied specifically for this client when connecting.If you want the raspberrypi client to have an IP address of 10.8.0.112. you need to create a file /etc/openvpn/ccd/raspberrypi
with this content:
$ sudo vi /etc/openvpn/ccd/raspberrypi
ifconfig-push 10.8.0.112 255.255.255.0
Next you need to restart OpenVPN
Regardless of the method you have chosen, you need to check if the changes have been applied. On the client device, enter the command:
$ ip -br a
We have looked at several ways to make static IP addresses for OpenVPN clients.