0

I have been running the ISC DHCP server on my Raspberry Pi 4B latest Buster build with a static IP which acts as the gateway, DHCP, DNS and IDS/IPS server on my home network. Following the online documentation, I was able to install, setup and get it up and running after a brief struggle.

In doing so, I also came across a bug in the ISC DHCP server that causes it not to start if there's an existing DHCPD (here and rather eloquently described here) file in /run/dhcpd.pid. Everytime I would test it out, I had to delete the /run/dhcpd.pid file and then it would work like a charm.

I had the worst time last evening when due to a brief electricity outage, the entire network infrastructure had to reboot (just the router, APs and the Pi). Since the DHCP was disabled on the router, other machines didn't not have a valid IP and for a brief period until I was able to set static IPs on some devices, my network was essentially useless. Since the Pi was operated headless, I had to google and find a way of connecting the Pi directly to my computer over LAN and then use the SSH to make amends.

The first thing I did was to try to see why the static IP settings wouldn't work. What made the Pi unreachable over the network? I couldn't figure out an obvious answer here except that the ISC DHCP server failed to start and probably that led to the Pi being unrecognizable over the network? That still didn't make a lot of sense to me considering I had set the static IPs in the network interfaces file.

The device would remain unreachable over the network until and unless I moved the DHCP control back into the router.

I then began experimenting with the idea of running a script at startup that would kill the DHCP process first, delete the /run/dhcpd.pid file and then restart the dhcpd service.

Here's what the shell script and the service files look like:

    /usr/bin/dhcpdrelease.sh
    
    #!/bin/sh
    set -e
    set echo off
    #sudo killall dhcpcd 
    #sudo rm -rf /run/dhcpd.pid 
    #sudo service isc-dhcp-server restart &
    
    
    chmod u+x /usr/bin/dhcpdrelease.sh
    
    /etc/systemd/system/dhcprelease.service

    [Unit]
    Description=DHCPD Release
    After=network.target
    RequiresMountsFor=/usr/bin/    
    
    [Service]
    ExecStart=/usr/bin/dhcpdrelease.sh
    
    [Install]
    WantedBy=multi-user.target
    
    sudo systemctl start dhcprelease
    sudo systemctl enable dhcprelease

This had no effect yet again. The Pi would again go unreachable over the network prompting me to again connect it over LAN, SSH and comment out the shell script.

I am an amateur at best when it comes to Unix and would not know how the DHCP daemon behaves in Unix/Pi OS or what is necessarily even the best way to run such a script at boot.

I'm merely trying to automate the following things upon reboot:

  1. The device have a valid IP and be reachable/pingable over network
  2. Delete the dhcp.pid file
  3. Restart ISC DHCP Service

I can't possibly have a network-wide breakdown in case of a power cycling.

I would like for the router to purely handle the wifi and the internet connection interface while delegating much of the muscle power to the Pi. Right now I have reverted the DHCP control back to the router while delegating only the DNS to the Pi. The network interfaces file has been reverted to taking the dynamic IP from the router. The IDS runs within this framework so its not necessarily the most effective. I would want the Pi to be the gateway for the network.

I strongly suspect that the DHCP service is to blame here but I'll admit having little to no clue whatsoever on how to fix this.

  • 1
    Guess: It's an issue how systemd/networkd and the ISC DHCP server interact. If you kill a ISC DHCP server under systemd control, systemd will try to restart it. When you then at the same time restart your own, things will get interesting. So you need to debug this on the systemd level. – dirkt Jul 4 at 10:29
0

Can't really call this an 'answer' as the bug has not been resolved and prevents one from an 'unmanaged' experience.

I just installed Pi-Hole and rolled the DNS, DHCP servers into one.

The network issue however took an interesting turn during my trials and errors yesterday. I noticed that when the code for static IP was enforced in the interfaces file, there would be severe problems with the interfaces. How I realized this was that I had an external wi-fi adapter connected to the USB port and it would show no signs of powering on. I then went on to comment out static IP enforcement in the network interfaces file and used only the /etc/dhcpd.conf. This might seem basic, obvious even but the network interfaces file had a clear instruction to deal with the static IP in the latter. I set that, reboot and viola!

"Houston, Tranquility base here. The Pi has landed."

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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