0

I would like to classify DHCP clients to be served an IP address from a pool defined in a subnet declaration in an ISC DHCPD's config file, and update the DNS server with that information.

Using option "dhcp-client-identifier" for clients to send the same class identifier wouldn't work, because a subsequent IP address request (from a different client) with the same identifier would tell the DHCP server that the previous client connected, instead of the latter, thus (trying to) update the DNS server with the new IP, loosing the entry for the previous client.

Resources I found on the Internet so far only talk about messing with existing options (usually vendor extensions) but nothing that would tell me what to do.

What I am thinking of doing is this:

  • Define a custom option
  • Configure client to send the class with an appropriate value
  • Define a client class on the server based on that option's value
  • Serve IP address according to the class

My approach is this:

DHCP Server, in /etc/dhcp/dhcpd.conf:

option foo code 224 = text; # code 224 - 250 is defined as local class range
...
class "myclass" {                   
   match if option foo ~= "value";
}
...
subnet xxx.xxx.xxx.xxx netmask 255.255.255.0 {
    pool {
        ...
        allow members of "myclass";
        deny known-clients;
    }
}

The DHCP server seem happy with at least the syntax:

root@ns:/home/michel# dhcpd -t -cf /etc/dhcp/dhcpd.conf.test
Internet Systems Consortium DHCP Server 4.3.1
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Config file: /etc/dhcp/dhcpd.conf.test
Database file: /var/lib/dhcp/dhcpd.leases
PID file: /var/run/dhcpd.pid
root@ns:/home/michel# 

(Don't kill me over being root - I did a "sudo bash" for convenience)

DHCP client, in /etc/dhcp/dhclient.conf:

# This is what I'd like the client to be able to send to make this all work
send foo "42";

I hope I am on the right track, but I think I am missing something here...

  • DHCP server: isc-dhcp-server/oldstable,now 4.3.1-6+deb8u2 armhf
  • DHCP clients: isc-dhcp-client/xenial-updates,now 4.3.3-5ubuntu12.7 amd64

Thanks, Michel

4

1 回答 1

3

让它以预期的方式工作,如下所示:

  • dhcp-options(5)(例如此处)对自定义选项的“定义”含糊不清
  • 确保使用 [224 - 254] 范围内的选项代码(参见手册页,“定义新选项”部分)
  • 实际的选项定义代码必须对客户端和服务器都可用;dhcp-options(5) 对此完全保持沉默。这就是让我感到疑惑和绊脚石的原因。您可以使用 include 语句从已挂载的文件系统中的任何位置加载定义,或者通过“神圣启蒙”,也称为代码复制(见下文)。
  • 自定义选项可以具有多种结构中的一种,从布尔值和字符串(“文本”)到复杂记录(类似于 C 或 PERL 中的结构),请参阅 dhcp.options(5) 了解更多信息。

工作示例

服务器和客户端的以下代码片段需要存在;它们显然适用于 ISC DHCP 服务器和客户端库。

在客户端;文件 /etc/dhcp/dhclient.conf

option foo code 224 = text; # here be divine enlightenment!
send foo "value";

在服务器上;文件 /etc/dhcp/dhcpd.conf

option foo code 224 = text;
class "myclass" {
    match if option foo ~= "value";
}

match 语句的 RHS 是一个正则表达式 - 用复杂的表达式调试你的心愿 ;-)

然后,您可以在 dhcpd.conf 中的任何其他限定语句中使用“myclass”类,例如,如原始问题中所示。

于 2017-12-18T19:35:26.470 回答