AI & Agents

How to Set Up a Raspberry Pi DHCP Server with dnsmasq

ISC's DHCP server reached end-of-life in October 2022, leaving dnsmasq as the lightweight standard for IP address management on small networks. This guide walks through installing dnsmasq on a Raspberry Pi, configuring DHCP ranges and static leases by MAC address, planning for Pi downtime, and combining DHCP with Pi-hole for ad-blocking and DNS on one device.

Fast.io Editorial Team 12 min read
Raspberry Pi DHCP server configuration with dnsmasq

Why a Raspberry Pi Beats Your Router for DHCP

ISC declared its DHCP server end-of-life on October 5, 2022, closing the book on two decades as the internet's default DHCP implementation. That left dnsmasq as the practical standard for lightweight address management, and with 7.6 million Raspberry Pi units shipped in FY 2025 alone, a growing number of those boards now handle IP assignments for home labs and small offices.

Your router's built-in DHCP works until you need something it can't do. Most consumer routers offer a narrow set of options: a DHCP range, a handful of static reservations through a sluggish web interface, and nothing resembling logs. A Raspberry Pi running dnsmasq gives you fine-grained control over every lease, static reservations by MAC address and hostname, DNS caching in the same process, and plain-text config files you can version and audit.

dnsmasq handles both DNS forwarding and DHCP in a single daemon. It runs comfortably on a Pi Zero and scales to hundreds of leases on any Pi model. The entire configuration lives in one file, /etc/dnsmasq.conf, or in drop-in snippets under /etc/dnsmasq.d/. Compared to Kea (ISC's heavyweight replacement for its deprecated DHCP server), dnsmasq takes minutes to configure and uses a fraction of the memory.

A Raspberry Pi DHCP server also gives you a platform to run additional network services. DNS-based ad blocking with Pi-hole, network monitoring, and even AI-assisted configuration management all run on the same device. The Pi becomes a network appliance you actually control.

Prerequisites: Static IP and Interface Setup

Before installing dnsmasq, your Pi needs a static IP address. A DHCP server that gets its own address from another DHCP server will cause problems the first time your router reboots.

Hardware you need:

  • A Raspberry Pi (any model with Ethernet, or Wi-Fi for wireless-only setups)
  • A microSD card with Raspberry Pi OS installed (Bookworm or later recommended)
  • An Ethernet cable connecting the Pi to your switch or router

Setting a static IP on Bookworm and later:

Raspberry Pi OS Bookworm switched from dhcpcd to NetworkManager. The fast way to set a static IP is nmtui:

sudo nmtui

Select "Edit a connection," choose your interface (typically eth0 for wired), and change IPv4 Configuration from "Automatic" to "Manual." Add your desired address (for example, 192.168.1.2/24), gateway (192.168.1.1), and DNS server.

On older Raspberry Pi OS versions (Bullseye and earlier):

Edit /etc/dhcpcd.conf directly:

interface eth0
static ip_address=192.168.1.2/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8

After setting the static IP, reboot and verify with ip addr show eth0. Confirm that the address matches what you configured before moving on. If the Pi still shows a DHCP-assigned address, NetworkManager may have reverted your change. Run nmcli connection show to check which profile is active and ensure the static configuration is applied to the right one.

Installing and Configuring dnsmasq

Install dnsmasq from the default repositories:

sudo apt update && sudo apt install dnsmasq -y

Stop the service before editing the configuration:

sudo systemctl stop dnsmasq

The default /etc/dnsmasq.conf is mostly comments. You can edit it in place or create a clean config file at /etc/dnsmasq.d/dhcp.conf. dnsmasq reads all .conf files in that directory automatically.

Here is a working configuration for a typical home or small office network:

interface=eth0
bind-dynamic
domain-needed
bogus-priv

dhcp-range=192.168.1.100,192.168.1.200,255.255.255.0,12h
dhcp-option=3,192.168.1.1
dhcp-option=6,192.168.1.2

domain=home.lan

What each line does:

  • interface=eth0 tells dnsmasq to listen only on the wired interface, not on localhost or other interfaces
  • bind-dynamic lets dnsmasq coexist with other services on the same host without port conflicts
  • domain-needed and bogus-priv prevent local queries from leaking to upstream DNS servers
  • dhcp-range defines the address pool: .100 through .200, with 12-hour leases
  • dhcp-option=3 sets the default gateway (your router's IP)
  • dhcp-option=6 points clients to the Pi for DNS, so they benefit from dnsmasq's DNS caching
  • domain=home.lan assigns a local domain name so devices can reach each other by hostname

Plan your DHCP range before you start. Reserve the lower portion of your subnet (.1 through .99) for devices with static IPs: the router, the Pi, printers, and any servers. Give dnsmasq the .100-.200 range for dynamic allocation. That leaves .201-.254 as room to grow.

Disable DHCP on your router before starting dnsmasq. Two DHCP servers on the same subnet create a race condition where clients get an address from whichever server responds first, leading to duplicate assignments and unpredictable behavior.

Start and enable the service:

sudo systemctl enable dnsmasq
sudo systemctl start dnsmasq

Test by connecting a device to the network and checking that it receives an address in the .100-.200 range. On the Pi, watch the log in real time with journalctl -u dnsmasq -f to see lease assignments as they happen.

Fastio features

Version your dnsmasq configs across every Pi

A workspace for network configuration files, runbooks, and documentation. Intelligence Mode makes your files searchable by meaning. Starts with a 14-day free trial.

Static Lease Assignments by MAC Address and Hostname

Static leases (also called DHCP reservations) assign the same IP to a specific device every time it connects. This is the feature that separates a Pi DHCP server from a router's basic interface, and it is where most tutorials stop short.

dnsmasq handles static leases with dhcp-host lines in the configuration:

dhcp-host=00:11:22:33:44:55,desktop-pc,192.168.1.50
dhcp-host=AA:BB:CC:DD:EE:FF,laser-printer,192.168.1.60
dhcp-host=11:22:33:44:55:66,22:33:44:55:66:77,laptop,192.168.1.70

Each line maps a MAC address to a hostname and a fixed IP. The third example handles a device with both wired and wireless interfaces by listing both MAC addresses.

Finding MAC addresses: Check your router's connected device list, or watch dnsmasq's log output. When a new device requests an address, dnsmasq logs the request along with the MAC:

grep "DHCPREQUEST" /var/log/syslog

On systems using journald instead of syslog, use journalctl -u dnsmasq | grep DHCPREQUEST.

Organizing reservations at scale: Once you have more than a dozen static leases, keeping them all in the main config file gets unwieldy. Create a dedicated file at /etc/dnsmasq.d/static-leases.conf for your reservations. dnsmasq loads every .conf file in /etc/dnsmasq.d/ at startup, so you can split your configuration across multiple files by function.

You can also assign IPs by hostname alone, without a MAC:

dhcp-host=home-nas,192.168.1.80

This matches the hostname the client sends in its DHCP request. It is less reliable than MAC-based assignment because clients can send any hostname they want, but it works well for VMs and containers where MAC addresses change on every restart.

After adding or changing leases, reload without dropping existing connections:

sudo systemctl reload dnsmasq

A reload re-reads all config files. Existing leases stay active, and the new reservations take effect on the next renewal cycle.

What Happens When the Pi Goes Down

If your Raspberry Pi DHCP server loses power or crashes, every device on your network keeps working, at least for a while. DHCP leases are time-based contracts, and clients hold their assigned address until the lease expires.

Clients attempt renewal at two specific points in the lease cycle:

  • At 50% of the lease time (T1), the client sends a unicast renewal directly to the server
  • At 87.5% of the lease time (T2), the client broadcasts a renewal request to any server on the subnet

With a 12-hour lease, devices will not attempt their first renewal for 6 hours. If the Pi comes back online before that, clients renew silently and nothing breaks. Even if the T1 renewal fails, clients keep retrying through the T2 window, giving you until the 87.5% mark before things get urgent.

If the Pi stays offline past lease expiry, devices lose their IP configuration and drop off the network. New devices that join can't get an address at all. DNS resolution also fails if clients were using the Pi for DNS.

Strategies to reduce the risk:

  • Extend your lease time. Change 12h to 24h or 48h in your dhcp-range. Longer leases buy more recovery time. The trade-off: released addresses stay "reserved" longer, which matters only on networks where devices come and go frequently.
  • Add a UPS. A small USB uninterruptible power supply keeps a Pi running through brief power outages, which are the most common cause of unexpected downtime.
  • Monitor the service. A cron job that checks systemctl is-active dnsmasq and sends an alert catches failures before leases start expiring. You can push alerts to a webhook, email, or a shared workspace where your team (or an agent) will see them.
  • Version your config files. Store your dnsmasq configuration in a workspace you can access from any device. If the Pi's SD card dies, you can flash a new card and restore the config in minutes rather than rebuilding from scratch. Fast.io gives you a workspace for storing config files, runbooks, and network documentation, and Intelligence Mode makes those files searchable by meaning rather than just filename. Every org starts with a 14-day free trial.

For environments where downtime isn't acceptable, run a second dnsmasq instance on another device with the same static lease configuration but a different, non-overlapping dynamic DHCP range. Both servers respond to requests, and clients accept whichever answer arrives first.

Running DHCP Alongside Pi-hole

Pi-hole blocks ads and trackers at the DNS level, and it ships with its own fork of dnsmasq. That means you can run DHCP, DNS, and ad-blocking on a single Raspberry Pi without installing a separate dnsmasq package.

Enabling DHCP in Pi-hole:

  1. Open the Pi-hole admin panel (typically at http://192.168.1.2/admin)
  2. Navigate to Settings, then DHCP
  3. Check "DHCP server enabled"
  4. Set your DHCP range and lease time
  5. Save and disable DHCP on your router

Pi-hole stores its dnsmasq configuration in /etc/dnsmasq.d/. You can add static lease files here using the same dhcp-host syntax covered earlier. Your existing /etc/dnsmasq.d/static-leases.conf file carries over without changes.

Why this combination works well: When Pi-hole handles both DNS and DHCP, it resolves hostnames for every device on your network. Instead of seeing "192.168.1.50 made 47 queries" in the Pi-hole dashboard, you see "desktop-pc made 47 queries." This makes troubleshooting and monitoring far more practical.

If you already have standalone dnsmasq running, disable it before enabling Pi-hole's DHCP:

sudo systemctl stop dnsmasq
sudo systemctl disable dnsmasq

Pi-hole's version of dnsmasq replaces the standalone one. Trying to run both causes port conflicts on UDP 67 and will prevent either from starting cleanly.

Keeping your configuration portable: Whether you run standalone dnsmasq, Pi-hole, or a combination across multiple sites, your .conf files contain the ground truth of your network. Store them somewhere that survives an SD card failure. A shared workspace with version history and AI-powered search lets you (or an agent) pull up the right config file by describing what you need rather than remembering the exact filename. Fast.io workspaces handle this well, and the MCP server at /storage-for-agents/ gives agents direct read and write access. Plans start with a 14-day free trial (Solo at $29/month, Business at $99/month), with storage, monthly credits, and workspaces scaled to each tier.

Frequently Asked Questions

Can a Raspberry Pi be used as a DHCP server?

Yes. Any Raspberry Pi model running Raspberry Pi OS can serve as a DHCP server by installing dnsmasq. The Pi assigns IP addresses, subnet masks, default gateways, and DNS server information to every device on your local network. Even a Pi Zero has enough resources to manage hundreds of DHCP leases.

How do I set up DHCP on a Raspberry Pi?

Install dnsmasq with `sudo apt install dnsmasq`, set a static IP on the Pi using `nmtui` (on Bookworm) or `/etc/dhcpcd.conf` (on older releases), then configure your DHCP range and options in `/etc/dnsmasq.conf` or a drop-in file under `/etc/dnsmasq.d/`. Disable DHCP on your router before starting the service to avoid conflicts.

Is dnsmasq better than isc-dhcp-server for a Raspberry Pi?

For most Pi deployments, yes. dnsmasq combines DNS caching and DHCP in a single lightweight daemon, uses minimal memory, and configures in minutes. ISC DHCP reached end-of-life in October 2022 and is no longer maintained. ISC recommends migrating to Kea, but Kea is designed for larger enterprise networks and carries more overhead than dnsmasq.

Can I run DHCP and Pi-hole on the same Raspberry Pi?

Yes. Pi-hole includes its own fork of dnsmasq, so you can enable DHCP directly from Pi-hole's admin panel under Settings then DHCP. You do not need to install standalone dnsmasq separately. When Pi-hole handles both DNS and DHCP, it can display device hostnames in the ad-blocking dashboard instead of raw IP addresses.

What happens to my network if the Raspberry Pi DHCP server goes down?

Devices already on the network keep their IP addresses until their DHCP lease expires. With a 12-hour lease, clients won't attempt their first renewal until the 6-hour mark. If the Pi comes back before leases expire, clients renew automatically. New devices joining during the outage won't receive an address. Setting longer lease times (24 or 48 hours) and using a UPS can reduce the impact of Pi downtime.

How do I assign a fixed IP address to a device using dnsmasq?

Add a `dhcp-host` line to your dnsmasq configuration with the device's MAC address, hostname, and desired IP. For example: `dhcp-host=00:11:22:33:44:55,my-server,192.168.1.50`. After saving, run `sudo systemctl reload dnsmasq` to apply the change without restarting the service or disrupting existing leases.

Related Resources

Fastio features

Version your dnsmasq configs across every Pi

A workspace for network configuration files, runbooks, and documentation. Intelligence Mode makes your files searchable by meaning. Starts with a 14-day free trial.