我使用的是 systemd 网络版本 253.1。我的 Linux 5.15 机器上有 2 个以太网端口,我想在第二个端口上设置一个 DHCP 服务器。我已成功完成此操作,并为 eth1 进行了以下配置。
工作 DHCP 服务器配置:
[Match]
Name=eth1
Type=ether
[DHCPV4]
DUIDType=link-layer
ClientIdentifier=mac
[Network]
Address=172.1.17.1/24
DHCPServer=yes
#IPMasquerade=ipv4
[DHCPServer]
PoolOffset=1
PoolSize=8
现在,我想要将范围更改为以下内容:
[Match]
Name=eth1
Type=ether
[DHCPV4]
DUIDType=link-layer
ClientIdentifier=mac
[Network]
#
# 10.1.193.24/29
#
# Network Address: 10.1.193.24
# Usable IP Range: 10.1.193.25 - 10.1.193.30
# Broadcast Address: 10.1.193.31
#
Address= 10.1.193.24/29
DHCPServer=yes
#IPMasquerade=ipv4
[DHCPServer]
PoolOffset=2
PoolSize=5
但是,我收到如下所示的错误:
[root@machine ~]$ networkctl status eth1 -l
* 3: eth1
Link File: n/a
Network File: /etc/systemd/network/eth1.network
State: routable (failed)
Online state: online
Type: ether
Path: platform-30bf0000.ethernet
Hardware Address: 00:01:c0:37:6d:56 (Company, Ltd.)
MTU: 1500 (min: 46, max: 9000)
QDisc: mq
IPv6 Address Generation Mode: eui64
Number of Queues (Tx/Rx): 8/8
Auto negotiation: yes
Speed: 1Gbps
Duplex: full
Port: tp
Address: 10.1.193.24
fe80::201:c0ff:fe37:6d56
Activation Policy: up
Required For Online: yes
DHCP6 Client DUID: DUID-EN/Vendor:0000ab1180dd9f24e9435b570000
Offered DHCP leases: none
Aug 12 14:33:07 machine systemd-networkd[654]: eth1: Received new foreign route (configured): dst: 10.1.193.24/29, src: n/a, gw: n/a, prefsrc: 10.1.193.24, scope: link, table: main(254), proto: kernel, type: unicast, nexthop: 0, priority: 0, flags: n/a
Aug 12 14:33:07 machine systemd-networkd[654]: eth1: Addresses set
Aug 12 14:33:07 machine systemd-networkd[654]: eth1: link_check_ready(): dynamic addresses or routes are not configured.
Aug 12 14:33:07 machine systemd-networkd[654]: eth1: Configuring DHCP Server.
Aug 12 14:33:07 machine systemd-networkd[654]: eth1: Failed to configure address pool for DHCPv4 server instance: Numerical result out of range
Aug 12 14:33:07 machine systemd-networkd[654]: eth1: Failed to configure DHCP server: Numerical result out of range
Aug 12 14:33:07 machine systemd-networkd[654]: eth1: Failed
Aug 12 14:33:07 machine systemd-networkd[654]: eth1: State changed: configuring -> failed
Aug 12 14:33:07 machine systemd-networkd[654]: eth1: LLDP Rx: Stopping LLDP client
Aug 12 14:33:07 machine systemd-networkd[654]: eth1: NDISC: Stopping IPv6 Router Solicitation client
我检查了各种 CIDR 计算器,我相信我的配置文件参数是有效的。
为什么 networkd 不接受我的配置文件?
我认为这里的问题是,这
10.1.193.24
是.0
此 CIDR 范围的地址;这就像将地址分配192.168.1.0
给网络上的主机一样192.168.1.0/24
。许多系统将其视为广播地址。它似乎systemd-networkd
不允许您将此地址分配给接口。以下配置对我来说很好用:
请注意减少的池大小,因为服务器地址为 10.1.193.25 且偏移量为
2
,我们有以下可用地址:10.1.193.31
是广播地址。提起这件事,我在日志中看到:
界面如下:
正如预期的那样,如果我在这个网络上启动五台机器,其中四台能够成功获取 DHCP 租约:
在上面的输出中,您可以看到
Reply
消息。地址处的主机52:54:00:09:97:9b
无法获取租约,因为所有可用地址都已分配给其他主机。