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:
- The device have a valid IP and be reachable/pingable over network
- Delete the dhcp.pid file
- 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.