大网数据广告活动
服务器运维问答

How to set a static IP (client side) in OpenVPN?

· 52CE 我爱测

I am setting up a VPN network with a lot of little devices (running OpenWRT). In my use case, the devices are all identified by a number and I would like their ip adresses to match their ID (e.g: the device number 6 will have an …

问题原文

原帖链接 · Morreski · CC BY-SA 3.0

I am setting up a VPN network with a lot of little devices (running OpenWRT). In my use case, the devices are all identified by a number and I would like their ip adresses to match their ID (e.g: the device number 6 will have an ip in X.X.X.6).

I am aware of client-config-dir and ifconfig-push but i cannot use them because all my devices use the same certificate (duplicate-cn is enabled). This is a requirement since generating one certificate for each devices will be too constraining (moreover, we don't want to change the configuration of the VPN server if we add a device in the system)

Is it possible to set the ip adress in the client configuration file ? I didn't found anything in the documentation about that particular topic... And everything I tried didn't succeed.

Basically, what I have in mind would be the following:

  • Client Connect to the VPN server and asks for a specific adress ("give me the ip: 172.16.0.22")
  • If the adress is already taken, the handshake fails. If it is free, the client is given the adress he asked before

已采纳解答

原帖链接 · jas_raj · CC BY-SA 3.0

You should be able to do this with the ifconfig-pool-persist config option. You can pre-configure the file and set seconds = 0 to tell OpenVPN to only read the file.

We use it to ensure the same user is assigned the same IP when connected via VPN for audit purposes.

From the man page:

--ifconfig-pool-persist file [seconds] Persist/unpersist ifconfig-pool data to file, at seconds intervals (default=600), as well as on program startup and shutdown. The goal of this option is to provide a long-term association between clients (denoted by their common name) and the virtual IP address assigned to them from the ifconfig-pool. Maintaining a long-term association is good for clients because it allows them to effectively use the --persist-tun option.

file is a comma-delimited ASCII file, formatted as ,.

If seconds = 0, file will be treated as read-only. This is useful if you would like to treat file as a configuration file.

Note that the entries in this file are treated by OpenVPN as suggestions only, based on past associations between a common name and IP address. They do not guarantee that the given common name will always receive the given IP address. If you want guaranteed assignment, use --ifconfig-push

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-01-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。