我有一个关于正确的isc-dhcpconfiguration的问题。 我想租用基于交换机端口的用户的IP地址。 为此,我使用DLink DES-3200系列交换机。 一切运作良好,但最近我决定租用特定的子网给所有未知的用户,即没有明确指定在dhcpd.conf文件。 这是一个configuration示例:#dhcpd.conf
default-lease-time 30; max-lease-time 60; authoritative; log-facility local7; option domain-name-servers 8.8.8.8; include "/usr/local/etc/dhcpd/dhcpd.classes"; shared-network "clients" { subnet 10.5.20.0 netmask 255.255.255.0 {} include "/usr/local/etc/dhcpd/dhcpd.networks"; }
dhcpd.classes
class "10.5.20.4_2" { match if ( substring(option agent.remote-id,2,15)="10.5.20.4" and binary-to-ascii(10, 16, "", substring(option agent.circuit-id, 4, 2)) = "2" ); } class "10.5.20.4_1" { match if ( substring(option agent.remote-id,2,15)="10.5.20.4" and binary-to-ascii(10, 16, "", substring(option agent.circuit-id, 4, 2)) = "1" ); } class "10.5.20.2_1" { match if ( substring(option agent.remote-id,2,15)="10.5.20.2" and binary-to-ascii(10, 16, "", substring(option agent.circuit-id, 4, 2)) = "1" ); } class "10.5.20.2_3" { match if ( substring(option agent.remote-id,2,15)="10.5.20.2" and binary-to-ascii(10, 16, "", substring(option agent.circuit-id, 4, 2)) = "3" ); } class "10.5.20.2_2" { match if ( substring(option agent.remote-id,2,15)="10.5.20.2" and binary-to-ascii(10, 16, "", substring(option agent.circuit-id, 4, 2)) = "2" ); } class "10.5.20.2_4" { match if ( substring(option agent.remote-id,2,15)="10.5.20.2" and binary-to-ascii(10, 16, "", substring(option agent.circuit-id, 4, 2)) = "4" ); }
dhcpd.networks
subnet 172.30.20.0 netmask 255.255.255.0 { option subnet-mask 255.255.255.0; option routers 172.30.20.1; pool {range 172.30.20.3; allow members of "10.5.20.4_2"; } pool {range 172.30.20.2; allow members of "10.5.20.4_1"; } } subnet 172.30.160.0 netmask 255.255.255.0 { option subnet-mask 255.255.255.0; option routers 172.30.160.1; pool {range 172.30.160.3; allow members of "10.5.20.2_1"; } pool {range 172.30.160.4; allow members of "10.5.20.2_3"; } pool {range 172.30.160.10; allow members of "10.5.20.2_2"; } pool {range 172.30.160.12; allow members of "10.5.20.2_4"; } }
所以如果添加添加让我们说:
subnet 172.20.111.0 netmask 255.255.255.0 { option routers 172.20.111.1; max-lease-time 60; min-lease-time 30; range 172.20.111.10 172.20.111.20 ; }
在dhcpd.networks文件的末尾(我将其包含到shared-network'clients'子句中,参见上文),我的所有客户端都从172.20.111.0范围开始获取IP地址,无论它们是否为其端口指定了类。
有没有办法使dhcpd服务器首先查看类声明,然后子网?
你写道你在dhcpd.conf文件的末尾添加了新的子网。 您需要将其添加到shared-network ,否则dhcpd将不会将这些networking视为替代scheme。
在阅读man dhcpd.conf并玩了一番之后,我通过对dhcpd.networks文件进行如下修改来实现我的目标:
subnet 172.20.111.0 netmask 255.255.255.0 { pool { option routers 172.20.111.1; max-lease-time 60; min-lease-time 30; range 172.20.111.10 172.20.111.20 ; deny members of "10.5.20.4_1"; deny members of "10.5.20.4_2"; deny members of "10.5.20.2_1"; # .... etc }
}
现在它按照我想要的方式工作,但我不确定它是否能够很好地扩展。
只是除了这个旧的,但仍然有效的线程。 它简化了子网部分,但是每个固定IP添加一行。
class "FastIP"{ match pick-first-value (option agent.circuit-id); }
和以前一样
class "IP-10.1.2.3" { match if option agent.circuit-id = "YourOp82Value"; }
为每个Op82值添加此值,以将固定IP客户从免费池中排除:子类“FixedIP”“YourOp82Value”;
在子网中:
deny members of "FixedIP"; pool { allow members of "IP-10.1.2.3" ; range 10.1.2.3 10.1.2.3; }
这样你就不必拥有许多拒绝行的子网部分。 一个会做。