Dhcp server is not starting when used with NetworkManager
name: Dhcp server is not starting when used with NetworkManager
about: isc-dhcp-server and NetworkManager
Describe the bug
When using isc-dhcp-server
with NetworkManager
after rebooting the PC isc-dhcp-server
service fails to start with error message:
No subnet declaration for enp1s0 (no IPv4 addresses).
** Ignoring requests on enp1s0. If this is not what
you want, please write a subnet declaration
in your dhcpd.conf file for the network segment
to which interface enp1s0 is attached. **
Not configured to listen on any interfaces!
Dhcp server is configured properly, if I run systemctl start isc-dhcp-server
it starts without issues.
To Reproduce
- Install
NetworkManager
and configure it as default network management service forsystemctl
, use static IP configuration. - Install
isc-dhcp-server
- Configure
isc-dhcp-server
(/etc/default/isc-dhcp-server
,/etc/dhcp/dhcpd.conf
) - Ensure dhcp server works fine and assigns IP addresses
- Reboot PC
Expected behavior
isc-dhcp-server
service is tarted after PC boots up.
Environment:
- ISC DHCP version: 4.4.1
- OS: Debian 11
Additional Information
Root cause of this issue is that the isc-dhcp-server
is started before NetowrkManager
assings IP to the network interface configured to use with dhcp server, regardless it is configured in isc-dhcp-server.service
file to wait for network-online.target
. This happends because NetworkManager-wait-online.service
uses internally nm-online
command witch only waits for starting service, not the connection.
I've found the solution for this issue in this topic: https://unix.stackexchange.com/a/560539
but it requires update of NetworkManager-wait-online.service
(remove -s
parameter from call to nm-online
).
Workaround for that issue is to update isc-dhcp-server.service
[Service]
section with:
Restart=on-failure
RestartSec=5s
Another workaround would be to add some delay (2 sec) to startup script /etc/init.d/isc-dhcp-server
.