我的 DHCP 服务器出了问题。重启后 isc-dhcp-server 无法就绪,因为网络(它使用 NetworkManager)尚未就绪。
我在 isc-dhcp-server 启动脚本中放置了一个睡眠命令,但是当服务器重新启动时,脚本删除了包含睡眠命令的行。
当网络准备就绪时,如何延迟 DHCP 启动或重新启动?以下是一些信息:
Linux 版本
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
日志控制
jan 09 07:50:22 server systemd[1]: Starting LSB: DHCP server...
jan 09 07:50:28 server isc-dhcp-server[579]: Launching IPv4 server only.
jan 09 07:50:30 server dhcpd[622]: WARNING: Host declarations are global. They are not limited to the scope you declared them in.
jan 09 07:50:30 server dhcpd[632]: WARNING: Host declarations are global. They are not limited to the scope you declared them in.
jan 09 07:50:31 server dhcpd[632]: Wrote 0 deleted host decls to leases file.
jan 09 07:50:31 server dhcpd[632]: Wrote 0 new dynamic host decls to leases file.
jan 09 07:50:31 server dhcpd[632]: Wrote 79 leases to leases file.
jan 09 07:50:31 server dhcpd[632]:
jan 09 07:50:31 server dhcpd[632]: No subnet declaration for enp32s0 (no IPv4 addresses).
jan 09 07:50:31 server dhcpd[632]: ** Ignoring requests on enp32s0. If this is not what
jan 09 07:50:31 server dhcpd[632]: you want, please write a subnet declaration
jan 09 07:50:31 server dhcpd[632]: in your dhcpd.conf file for the network segment
jan 09 07:50:31 server dhcpd[632]: to which interface enp32s0 is attached. **
jan 09 07:50:31 server dhcpd[632]:
jan 09 07:50:31 server dhcpd[632]:
jan 09 07:50:31 server dhcpd[632]: Not configured to listen on any interfaces!
jan 09 07:50:31 server dhcpd[632]:
jan 09 07:50:31 server dhcpd[632]: If you think you have received this message due to a bug rather
jan 09 07:50:31 server dhcpd[632]: than a configuration issue please read the section on submitting
jan 09 07:50:31 server dhcpd[632]: bugs on either our web page at www.isc.org or in the README file
jan 09 07:50:31 server dhcpd[632]: before submitting a bug. These pages explain the proper
jan 09 07:50:31 server dhcpd[632]: process and the information we find helpful for debugging.
jan 09 07:50:31 server dhcpd[632]:
jan 09 07:50:31 server dhcpd[632]: exiting.
jan 09 07:50:33 server isc-dhcp-server[579]: Starting ISC DHCPv4 server: dhcpdcheck syslog for diagnostics. ...
jan 09 07:50:33 server isc-dhcp-server[640]: failed!
jan 09 07:50:33 server isc-dhcp-server[641]: failed!
jan 09 07:50:33 server systemd[1]: isc-dhcp-server.service: Control process exited, code=exited, status=1/FAILURE
jan 09 07:50:33 server systemd[1]: isc-dhcp-server.service: Failed with result 'exit-code'.
jan 09 07:50:33 server systemd[1]: Failed to start LSB: DHCP server.
#> cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
#> cat /etc/dhcp/dhcpd.conf
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
option domain-name "server.local";
option domain-name-servers 8.8.8.8, 8.8.4.4;
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
authoritative;
subnet 192.168.1.0 netmask 255.255.255.0 {
# — default gateway
option routers 192.168.1.3;
option subnet-mask 255.255.255.0;
#option nis-domain "SERVER";
option domain-name "SERVER";
# Cloudflare
option domain-name-servers 1.1.1.1, 1.0.0.1;
option time-offset -18000;
option ntp-servers 192.168.1.3;
#option tftp-server-name "192.168.1.10";
option broadcast-address 192.168.1.255;
range 192.168.1.11 192.168.1.90;
default-lease-time 21600;
max-lease-time 43200;
# Fixed IP addresses can also be specified for hosts.
[...]
感谢你们。
答案1
要在网络启动后启动服务,请After=network-online.target
在 systemd 服务文件中进行设置。
不要使用After=NetworkManager-wait-online.service
,因为那是一个实现细节。ordersNetworkManager-wait-online.service
本身Before=network-online.target
,因此您可以隐式地获得该顺序。
例如,通过 进行操作systemctl edit isc-dhcp-server.service
。
阅读手册页,特别是关于ipv4.may-fail=no
如何ipv4.required-timeout
告诉 NetworkManager 该接口仅准备好使用 IPv4 地址。
一个更好、更强大的解决方案可能是说服 DHCP 服务器在地址尚未出现时动态地应对启动。
答案2
您可以尝试做的是
systemctl enable systemd-networkd.service systemd-networkd-wait-online.service
进而
[Unit]
After=systemd-networkd-wait-online.service
Wants=systemd-networkd-wait-online.service
/etc/systemd/system/
我通常直接用 vi 或 nano编辑文件
然后执行 systemctl daemon-reload 并重新启动(如果服务正常启动)