目的
OS起動後にDHCPサーバーを自動的に実行させたい。
DHCPサーバーを機能させること自体はできましたが、systemdを使用してのサービス起動に失敗してしまいます。
OS起動後にSystemdを使用してStartすると成功します。
おそらく、Systemdの登録設定ファイルであるisc-dhcp-server.service(自作ファイル)において、なんらかの起動待ちをしなければならないと予想しておりますが、どういう記述をすればよいかが分かりません。
ご教示をお願いします。
環境
OS:Debian11
インストール
apt install isc-dhcp-server
インストール後に/etc/init.d以下に配置される。
/etc/init.d/isc-dhcp-server
設定
関連設定ファイル
/etc/default/isc-dhcp-server
# Defaults for isc-dhcp-server (sourced by /etc/init.d/isc-dhcp-server)
# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf).
DHCPDv4_CONF=/etc/dhcp/dhcpd.conf
#DHCPDv6_CONF=/etc/dhcp/dhcpd6.conf
# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
#DHCPDv4_PID=/var/run/dhcpd.pid
#DHCPDv6_PID=/var/run/dhcpd6.pid
# Additional options to start dhcpd with.
# Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead
#OPTIONS=""
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4="eth0"
#INTERFACESv6=""
/etc/dhcp/dhcpd.conf
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.100;
option routers 192.168.1.4;
option domain-name-servers 8.8.8.8, 8.8.4.4;
option broadcast-address 192.168.1.255;
}
設定動作確認
sudo /etc/init.d/isc-dhcp-server start
DHCPサーバーが動作していることを確認しました。
サービス起動設定
以下のファイルを作成し、/etc/systemd/system以下に配置。
isc-dhcp-server.service
[Unit]
Description=DHCP server - isc-dhcp-server
Before=network.target
Before=nss-lookup.target
[Service]
ExecStart=/etc/init.d/isc-dhcp-server start
ExecStop=/etc/init.d/isc-dhcp-server stop
Type=forking
PIDFile=/var/run/dhcpd.pid
[Install]
WantedBy=multi-user.target
サービスを有効化
systemctl enable isc-dhcp-server.service
$ systemctl list-unit-files --type=service | grep isc-dhcp
isc-dhcp-sever.service enabled enabled
OS起動時
OS起動時にサービス実行が失敗します。
$ systemctl status isc-dhcp-server.service
● isc-dhcp-server.service - DHCP server - isc-dhcp-server
Loaded: loaded (/etc/systemd/system/isc-dhcp-server.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2024-03-21 16:15:29 JST; 1min 21s ago
Process: 960 ExecStart=/etc/init.d/isc-dhcp-server start (code=exited, status=1/FAILURE)
CPU: 120ms
Mar 21 16:15:27 linaro-alip dhcpd[1090]: bugs on either our web page at www.isc.org or in the README file
Mar 21 16:15:27 linaro-alip dhcpd[1090]: before submitting a bug. These pages explain the proper
Mar 21 16:15:27 linaro-alip dhcpd[1090]: process and the information we find helpful for debugging.
Mar 21 16:15:27 linaro-alip dhcpd[1090]:
Mar 21 16:15:27 linaro-alip dhcpd[1090]: exiting.
Mar 21 16:15:29 linaro-alip isc-dhcp-server[960]: Starting ISC DHCPv4 server: dhcpdcheck syslog for diagnostics. ...
Mar 21 16:15:29 linaro-alip isc-dhcp-server[1140]: failed!
Mar 21 16:15:29 linaro-alip isc-dhcp-server[1141]: failed!
Mar 21 16:15:29 linaro-alip systemd[1]: isc-dhcp-server.service: Failed with result 'exit-code'.
Mar 21 16:15:29 linaro-alip systemd[1]: Failed to start DHCP server - isc-dhcp-server.
手動で起動すると、成功します。
$ systemctl start isc-dhcp-server.service
$ systemctl status isc-dhcp-server.service
● isc-dhcp-server.service - DHCP server - isc-dhcp-server
Loaded: loaded (/etc/systemd/system/isc-dhcp-server.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2024-03-21 16:18:44 JST; 3s ago
Process: 2015 ExecStart=/etc/init.d/isc-dhcp-server start (code=exited, status=0/SUCCESS)
Main PID: 2030 (dhcpd)
CPU: 148ms
CGroup: /system.slice/isc-dhcp-server.service
└─2030 /usr/sbin/dhcpd -4 -q -cf /etc/dhcp/dhcpd.conf eth0
Mar 21 16:18:42 linaro-alip isc-dhcp-server[2015]: Launching IPv4 server only.
Mar 21 16:18:42 linaro-alip dhcpd[2030]: Wrote 10 leases to leases file.
Mar 21 16:18:42 linaro-alip dhcpd[2030]: Server starting service.
Mar 21 16:18:42 linaro-alip dhcpd[2030]: DHCPREQUEST for 192.168.1.14 from 00:03:30:20:c0:04 (00033020C004) via eth0
Mar 21 16:18:42 linaro-alip dhcpd[2030]: DHCPACK on 192.168.1.14 to 00:03:30:20:c0:04 (00033020C004) via eth0
Mar 21 16:18:44 linaro-alip isc-dhcp-server[2015]: Starting ISC DHCPv4 server: dhcpd.