Deploying a Tiny DHCP Server on Raspberry Pi and IoT GearA tiny DHCP server can be a powerful tool for hobbyists, makers, and system integrators who manage small networks of embedded devices. Unlike full-fledged DHCP suites used in enterprise environments, a tiny DHCP server focuses on minimal resource use, simplicity, and easy configuration — ideal for Raspberry Pi units, microcontrollers, and other IoT gear that need basic network bootstrapping without the overhead of complex infrastructure.
This article covers why you might choose a tiny DHCP server, common use cases with Raspberry Pi and IoT devices, available lightweight implementations, step‑by‑step deployment on Raspberry Pi, security considerations, troubleshooting tips, and a short roadmap for extending functionality.
Why choose a tiny DHCP server?
- Low resource usage: Runs comfortably on low‑power hardware (Raspberry Pi Zero, single‑board computers, even some microcontrollers).
- Simplicity: Easier configuration, fewer dependencies, and smaller attack surface than full DHCP suites.
- Focused feature set: Provides essential DHCP features — lease allocation, static reservations, and option setting — without extra services you don’t need.
- Determinism: Predictable behavior for small networks and lab/test environments.
- Portability: Simple codebases that are easy to cross‑compile or run on alternative OSes.
Common alternatives include isc-dhcp-server (feature-rich but heavy), dnsmasq (lightweight and popular but broader in scope), and dedicated tiny DHCP projects written specifically for embedded targets.
Typical use cases
- Provisioning Raspberry Pi clusters in classroom or lab settings.
- Giving IP addresses to sensors, cameras, and other IoT endpoints in a home automation setup.
- Bootstrapping devices during automated testing or manufacturing (PXE-like workflows with minimal DHCP features).
- Running an isolated network for development where you want to avoid interacting with corporate DHCP.
- Creating portable, offline networks for demos and field work.
Lightweight DHCP implementations to consider
- dnsmasq — Popular lightweight package that offers DHCP + DNS + TFTP. Great balance of features and simplicity.
- BusyBox udhcpd (often just udhcpd) — Extremely small, used in many embedded Linux systems.
- TinyDHCP/Tiny-dhcpd — Small standalone implementations (look for community projects on GitHub).
- Custom minimal server — When you need precise behavior or to embed DHCP support into firmware.
Comparison (high level):
Implementation | Footprint | Key features | Good for |
---|---|---|---|
dnsmasq | Small–Moderate | DHCP, DNS, TFTP, caching | Home labs, Pi clusters, small networks |
udhcpd (BusyBox) | Very small | Basic DHCP leasing, static leases | Embedded systems, constrained devices |
Tiny‑dhcpd (projects) | Very small | Minimal DHCP options | Custom embedded builds, academic projects |
Custom server | Variable | Exactly what you implement | Specialized hardware, research |
Preparing the Raspberry Pi
-
Hardware:
- Raspberry Pi (Zero W, 3, 4, or Compute Module) or equivalent SBC.
- SD card with Raspberry Pi OS (Lite recommended for headless setups).
- Power supply, Ethernet cable (or USB‑to‑Ethernet for Zero W), optional USB console.
-
Software:
- Updated OS: run sudo apt update && sudo apt upgrade.
- Decide which DHCP server: dnsmasq is recommended for most Pi use cases; udhcpd for constrained installs; or a tiny custom binary for extreme minimalism.
-
Network layout planning:
- Decide the interface that will serve DHCP (eth0, wlan0 in AP mode, or a USB gadget interface).
- Define IP range, gateway, DNS, lease time, and any static reservations.
- Ensure the Pi is the only DHCP server on that network segment to avoid conflicts.
Example: Deploying dnsmasq as a tiny DHCP server
dnsmasq is small, well‑maintained, and supports DHCP and DNS. This example configures a Pi to serve DHCP on eth0 with a private subnet for IoT devices.
-
Install dnsmasq:
sudo apt update sudo apt install dnsmasq
-
Stop the service before editing:
sudo systemctl stop dnsmasq
-
Backup default config and create a minimal config file:
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig sudo tee /etc/dnsmasq.conf > /dev/null <<'EOF' interface=eth0 bind-interfaces dhcp-range=192.168.50.50,192.168.50.150,12h dhcp-option=3,192.168.50.1 # gateway dhcp-option=6,8.8.8.8,8.8.4.4 # DNS servers dhcp-host=00:11:22:33:44:55,192.168.50.10 # static lease example log-dhcp EOF
-
Assign a static IP to the Pi on eth0 (Raspberry Pi OS using dhcpcd): Edit /etc/dhcpcd.conf and add:
interface eth0 static ip_address=192.168.50.1/24 nogateway
Then restart dhcpcd:
sudo systemctl restart dhcpcd
-
Start dnsmasq and enable on boot:
sudo systemctl start dnsmasq sudo systemctl enable dnsmasq
-
Verify leases and logs:
- Leases: /var/lib/misc/dnsmasq.leases
- Logs: sudo journalctl -u dnsmasq -f or /var/log/syslog
Notes:
- If using the Pi as a Wi‑Fi access point (hostapd), point dnsmasq at the wlan0 interface and ensure hostapd starts before dnsmasq (or use systemd dependencies).
- For isolated testing, connect devices to a switch/hub that’s connected only to the Pi.
Example: Using BusyBox udhcpd for minimal footprint
udhcpd is extremely small and common in embedded Linux builds.
-
Install BusyBox udhcpd (often packaged as udhcpd):
sudo apt update sudo apt install udhcpd
-
Configure /etc/udhcpd.conf (example):
start 192.168.60.50 end 192.168.60.150 interface eth0 remaining yes option subnet 255.255.255.0 option router 192.168.60.1 option dns 1.1.1.1 opt lease 864000
-
Set Pi static IP for the serving interface similar to the dnsmasq example, then start udhcpd:
sudo systemctl enable udhcpd sudo systemctl start udhcpd
Limitations: udhcpd supports fewer DHCP options and has simpler lease handling compared to dnsmasq.
Static reservations and MAC-based assignments
Static mapping is essential for devices that need consistent addresses (e.g., cameras, gateways). In dnsmasq use dhcp-host=MAC,IP or add hostname. In udhcpd you can put static entries in a hosts file or similar facility depending on the implementation. For custom servers, add a small datastore (JSON, CSV) mapping MAC → IP and load at startup.
Example dnsmasq entry:
dhcp-host=AA:BB:CC:DD:EE:FF,192.168.50.20,device-name,24h
Security and reliability considerations
- Avoid running multiple DHCP servers on the same segment — leads to address conflicts.
- Restrict the DHCP server to the intended interface (interface= in dnsmasq) to prevent accidental exposure.
- Keep lease files and configs backed up. In small deployments, a single config change can disconnect many devices.
- Use firewall rules (iptables/nftables) to control which clients can reach services on the Pi if your network is untrusted.
- Log DHCP activity and rotate logs to aid troubleshooting.
- For manufacturing or provisioning workflows, consider short lease times and scripted static assignments.
Troubleshooting checklist
- Client not getting IP: ensure DHCP server is running and bound to the correct interface; check cable/AP connectivity.
- Conflicting DHCP: scan the network for other DHCP offers (tcpdump -i eth0 -nn -vv ‘port 67 or port 68’).
- Static lease not applied: verify MAC address format and that the lease file doesn’t already assign different values.
- IP range exhausted: expand dhcp-range or decrease lease time.
- Wireless AP issues: ensure hostapd and DHCP are coordinated; sometimes hostapd needs to be restarted after DHCP changes.
Useful commands:
- sudo journalctl -u dnsmasq -f
- tail -f /var/log/syslog
- sudo ss -lntu (check ports)
- sudo tcpdump -i eth0 port 67 or port 68 -n -vv
Extending functionality
- Add DNS: let dnsmasq provide simple local DNS names for devices using dhcp-host mappings.
- TFTP/PXE: combine dnsmasq with a TFTP server for lightweight network booting of devices.
- Web UI: a simple web interface can manage static reservations and view leases; many community projects exist, or write a small Flask app to edit config files and reload the service.
- High availability: for slightly larger deployments, use DHCP failover concepts or run multiple servers on separate VLANs, but true HA for DHCP quickly increases complexity and may be overkill for IoT setups.
Conclusion
Deploying a tiny DHCP server on a Raspberry Pi or other IoT hardware is straightforward and immensely useful for small, controlled networks. dnsmasq offers an excellent balance of features and footprint for most scenarios; udhcpd or tiny custom servers serve constrained environments or specialized firmware. Plan your IP addressing, secure the serving interface, and keep configurations backed up. With a compact DHCP server in place you gain fast, reliable network bootstrapping for Raspberry Pi clusters, sensors, cameras, and other IoT gear.
Leave a Reply