7

I'm having an issue with isc-dhcp-server. When I reboot I can see that it loads because it says "Starting LSB: DHCP server ...". However when trying to connect a PXE node to the server it does not work and I need to exectute "sudo service isc-dhcp-server restart". I have another PXE server that I've set up successfully that, for whatever reason, does not exhibit this issue. This is all on Raspbian Jessie. I also want to add that upon installation of isc-dhcp-server I get:

Job for isc-dhcp-server.service failed. See 'systemctl status isc-
dhcp-server.service' and 'journalctl -xn' for details.
invoke-rc.d: initscript isc-dhcp-server, action "start" failed.

Which is strange because in the past I've never had problems installing isc-dhcp-server. And I'm talking a week maybe two weeks in the past. So it seems like some sort of package update has borked it?

This the output of the command requested in the comments.

● isc-dhcp-server.service - LSB: DHCP server
Loaded: loaded (/etc/init.d/isc-dhcp-server)
Active: failed (Result: exit-code) since Mon 2017-07-31 07:59:29 EDT; 
17min ago

Jul 31 07:59:27 raspberrypi dhcpd[11899]: 
Jul 31 07:59:27 raspberrypi dhcpd[11899]: No subnet declaration for 
eth0 (10.0.0.73).
Jul 31 07:59:27 raspberrypi dhcpd[11899]: ** Ignoring requests on 
eth0.  If this is not what
Jul 31 07:59:27 raspberrypi dhcpd[11899]: you want, please write a 
subnet declaration
Jul 31 07:59:27 raspberrypi dhcpd[11899]: in your dhcpd.conf file for 
the network segment
Jul 31 07:59:29 raspberrypi isc-dhcp-server[11891]: Starting ISC DHCP 
server: dhcpdcheck syslog for diagnostics. ... failed!
Jul 31 07:59:29 raspberrypi isc-dhcp-server[11891]: failed!
Jul 31 07:59:29 raspberrypi systemd[1]: isc-dhcp-server.service: 
control process exited, code=exited status=1
Jul 31 07:59:29 raspberrypi systemd[1]: Failed to start LSB: DHCP 
server.
Jul 31 07:59:29 raspberrypi systemd[1]: Unit isc-dhcp-server.service 
entered failed state.

Can someone please help? Thanks!

chaoticslacker
  • 347
  • 1
  • 2
  • 12

3 Answers3

11

The reason why the ISC DHCPv4 server service fails is that at the time it is started the network interface configuration might not have been finished. As systemd cannot know when a service really has become ready (as opposed to have been started successfully), the usual start dependency service unit settings don't help either. Often, you'll find ugly workarounds using /etc/rc.local in combination with sleep 5 or something similar. Luckily, there's a better systemd way to do it (that is actually one of the features where I consider systemd to be better than previous init systems).

From my own experience with an Raspberry Pi 3B with an additional wlan1 USB WLAN dongle as an AP, I came up with an automatic restart of the DHCPv4 server in case it fails because it was too early.

  1. sudo cp /run/systemd/generator.late/isc-dhcp-server.service /etc/systemd/system
  2. sudo nano /etc/systemd/system/isc-dhcp-server.service
  3. Edit the [Service] section:
    • set Restart=on-failure,
    • add RestartSec=5 to instruct systemd to wait 5 seconds before restarting a failed service.
  4. Add the [Install] section which is missing, and add the follow line to it:
    • WantedBy=multi-user.target
  5. sudo systemctl daemon-reload
  6. sudo systemctl disable isc-dhcp-server
  7. sudo systemctl enable isc-dhcp-server

This tells systemd to automatically restart the ISC DHCPv4 server if it fails, but to wait 5 seconds before attempting to restart it. If this works for you, you can try to reduce the sleep time; it defaults to 100ms, which is probably much small for this situation.

TheDiveO
  • 1,591
  • 1
  • 11
  • 16
0

I had the same problem, but because my dhcp server managed two interfaces, it didn't crash on error.

I add multiple After= in its unit file /lib/systemd/system/isc-dhcp-server.service:

After=networking.service
After=hostapd.service

So I am sure it starts when the services using my wifi card are done starting. I could also add a ExecStartPre=sleep 10, for extra security.

Hugal31
  • 101
  • 3
0

The first answer (Restart=on-failure) didn't work for me. Apparently because nothing was "failing". The status was "Active: active (exited)".

The second answer (After=hostapd.service) also did not work. As explained, it's still too fast.

The second-and-a-half answer (ExecStartPre=sleep 5) did work.

At least I assume that's what did it. All three changes are there.

Tiger
  • 1
  • 1