Debian 11 为 2 个或更多客户端网络设置 DHCP

Debian 11 为 2 个或更多客户端网络设置 DHCP

我在 proxmox 服务器上有 2 个网桥(vmbr1 vmbr2)。

vmbr1 IP:NAT 客户端的 192.168.106.1

vmbr2 IP:192.168.107.1 仅适用于本地

我已经设置了 DHCP 服务器 (isc-dhcp-server),它与一个网段(在 vmbr1 上)完美配合。

当我尝试设置第二个网段 (vmbr2) 时,DHCP 服务器失败并显示以下消息:

No subnet declaration for vmbr2 (no IPv4 addresses).
** Ignoring requests on vmbr2.  If this is not what
   you want, please write a subnet declaration
   in your dhcpd.conf file for the network segment
   to which interface vmbr2 is attached. **

对于这个错误,这个语句显然应该解决这个问题:

subnet-mask 255.255.255.0;

然而,错误就变成了这样:

 isc-dhcp-server.service: Control process exited, code=exited, status=1/FAILURE
 If you think you have received this message due to a bug rather
 isc-dhcp-server.service: Failed with result 'exit-code'.
 than a configuration issue please read the section on submitting
 Failed to start LSB: DHCP server.
 bugs on either our web page at www.isc.org or in the README file
 before submitting a bug.  These pages explain the proper
 process and the information we find helpful for debugging.

 exiting.

这是工作的 /etc/default/isc-dhcp-server:

INTERFACESv4="vmbr1"
#INTERFACESv4="vmbr1 vmbr2"
#INTERFACESv6=""

这是工作的/etc/dhcp/dhcpd.conf:

option domain-name "mydomain.ca";
option domain-name-servers 8.8.8.8,8.8.4.4;
  
subnet 192.168.106.0 netmask 255.255.255.0 {
range 192.168.106.20 192.168.106.150;
#subnet-mask 255.255.255.0;
option routers 192.168.106.1;
}

#subnet 192.168.107.0 netmask 255.255.255.0 {
#range 192.168.107.20 192.168.107.150;
#subnet-mask 255.255.255.0;
#option routers 192.168.107.1;
#}

引起问题的选项已被注释掉。

有任何想法吗?

答案1

不,它不是要求您添加一行

subnet-mask 255.255.255.0;

没有这样的指令subnet-mask。你的想法可能是option subnet-mask;但是,这不是必需的,因为掩码已在子网声明(即subnet x.x.x.x netmask y.y.y.y { ... }块)中指定。

想要查看具有与当前配置的设置匹配的网络地址和掩码的块No subnet declaration for vmbr2的意思。dhcpdsubnet ... { ... }vmbr2

dhcpd.conf这是准备为两个子网提供服务的工作的更正版本:

option domain-name "mydomain.ca";
option domain-name-servers 8.8.8.8,8.8.4.4;
  
subnet 192.168.106.0 netmask 255.255.255.0 { # <-- subnet mask already specified here
range 192.168.106.20 192.168.106.150;
##subnet-mask 255.255.255.0;  <--- this line should be deleted
option routers 192.168.106.1;
}

subnet 192.168.107.0 netmask 255.255.255.0 { # <-- subnet mask already specified here
range 192.168.107.20 192.168.107.150;
##subnet-mask 255.255.255.0;  <--- this line should be deleted
option routers 192.168.107.1;
}

您显然是通过输出查看错误消息systemctl status isc-dhcp-server.service。您应该注意,它仅显示实际输出的最后 10 行。验证 DHCP 服务器配置语法是否正确的更好方法是-t使用dhcpd.

当我将原始的“工作/etc/dhcp/dhcpd.conf”保存为/tmp/dhcpd.conf.test,取消注释第一subnet-mask行并运行时dhcpd -cf /tmp/dhcpd.conf.test -t,以下是完整输出:

# dhcpd -cf /tmp/dhcpd.conf.test -t
Internet Systems Consortium DHCP Server 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
/tmp/dhcpd.conf.test line 6: semicolon expected.
subnet-mask 255.
             ^
Configuration file errors encountered -- exiting

If you think you have received this message due to a bug rather
than a configuration issue please read the section on submitting
bugs on either our web page at www.isc.org or in the README file
before submitting a bug.  These pages explain the proper
process and the information we find helpful for debugging.

exiting.

请注意,最后的措辞可能会导致您错过重要的部分:

/tmp/dhcpd.conf.test line 6: semicolon expected.
subnet-mask 255.
             ^
Configuration file errors encountered -- exiting

表明subnet-mask不应该这样使用。

相关内容