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!

6
  • What does sudo systemctl -l isc-dhcp-server say? Does the ISC DHCP server stop because it cannot find any subnets (yet) to serve?
    – TheDiveO
    Commented Jul 31, 2017 at 5:39
  • It says unknown operation 'isc-dhcp-server' . Did you mean sudo systemctl status isc-dhcp-server? Because that doesn't give much information other than the service failed to start. Also, when installing the program 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. Commented Jul 31, 2017 at 12:04
  • sorry, I forgot the operation, so it's sudo systemctl status -l isc-dhcp-server. This gives the status of the service, as well as the messages it logged.
    – TheDiveO
    Commented Jul 31, 2017 at 12:05
  • 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! Commented Jul 31, 2017 at 12:10
  • Ah, I should have an answer for you know... :)
    – TheDiveO
    Commented Jul 31, 2017 at 12:10

3 Answers 3

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.

1
  • @chaoticslacker Please note that I've updated my answer after I noticed some issues on my own installation regarding the missing [Install] section and the correct reregistering of the service.
    – TheDiveO
    Commented Jul 31, 2017 at 13:04
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.

4
  • You cannot set dependencies on config files. You can can only set it to Units (services, targets, timers etc.) because the config files does not signal that it have started.
    – Ingo
    Commented Oct 31, 2019 at 16:58
  • Sorry, I miss-wrote the configuration in my answer. It's fixed now.
    – Hugal31
    Commented Oct 31, 2019 at 17:04
  • I think it is better to use After=network-online.target because it includes the network services and guarantees that network is online. I'm not sure but I believe isc-dhcp-server.service already include it. You can check it with systemctl cat isc-dhcp-server.service.
    – Ingo
    Commented Oct 31, 2019 at 17:09
  • Yes, it already had After=network-online.target. The dependency to hostapd did probably helped more, but it is related to my own problem.
    – Hugal31
    Commented Oct 31, 2019 at 17:18
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.

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Feb 19, 2022 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.