Pi-hole Docker Setup: Network-Wide Ad Blocking & DHCP
I was doing some Googling the other day for a quick reference and clicked on the first result without really looking. All of a sudden, bam! Popup after popup started screaming that my computer was infected with every virus known to man, my browser locked up, and a robotic voice told me I needed to call “Microsoft Support” immediately before my hard drive melted. I closed the tab, shook my head at myself for clicking a sponsored link, and realized it was finally time to put a real bouncer at the front door of my home network.
That bouncer is Pi-hole. If you think of DNS like the internet’s phone book, Pi-hole is basically Dalton from Road House standing at the door, politely tossing out known ad servers, trackers, and sketchy scam domains before your devices ever talk to them.
Why Run Pi-hole and Let It Handle DHCP
Putting an ad blocker on every phone, laptop, smart TV, and streaming box in your house gets old fast. Pi-hole solves that at the network level, and letting it take over Dynamic Host Configuration Protocol (DHCP) makes the setup even better:
- Zero client installs: Once Pi-hole handles DNS for your network, ads and malicious domains get blocked on devices that can’t even run browser extensions, like your smart TV or game console.
- Faster page loads and less bandwidth wasted: Your devices never download the ad scripts or tracking pixels in the first place.
- Per-device visibility: If your router points everyone to Pi-hole on its own, every single DNS request in your dashboard looks like it came from the router. When Pi-hole acts as your DHCP server, you see exactly which device is making which requests.
- Works around locked-down ISP routers: Many ISP-provided routers don’t let you change the DNS server they hand out over DHCP. Disabling DHCP on the router and letting Pi-hole hand out IP addresses and DNS settings bypasses that limitation completely.
- Easy static leases: You can assign static IP addresses to your homelab servers and printers right from the Pi-hole web interface.
| Feature | Router DHCP + Pi-hole DNS | Pi-hole DHCP + DNS |
|---|---|---|
| Works on locked-down ISP routers | Often no | Yes |
| Per-device query logs in Pi-hole | Usually shows only the router IP | Shows individual device IPs and hostnames |
| Static IP management | Managed on the router | Managed directly in Pi-hole |
| Docker network requirement | Standard bridge mode works | Requires host or macvlan networking |
What You Need Before Starting
Make sure you have these four things lined up before you spin up the container:
- A Linux host running Docker and Docker Compose (Docker Desktop on Windows or macOS has limitations with
hostnetworking for LAN DHCP broadcasts, so a Linux box or VM is the way to go). - A static IP address configured on that Docker host so your DNS and DHCP server never changes addresses on you.
- Admin access to your router so you can turn off its built-in DHCP server when Pi-hole is ready to take over.
- SSH or terminal access to your Docker host.
Installing the Pi-hole Container
- Create a dedicated directory on your host for Pi-hole and move into it. This keeps your Compose file and persistent data together so you can back them up or move them later.
mkdir -p ~/docker/pihole && cd ~/docker/pihole
Code language: Bash (bash)
- Create a
docker-compose.ymlfile with the configuration below. Because Pi-hole will be your DHCP server, it needsnetwork_mode: hostso it can hear Layer 2 DHCP broadcast traffic on UDP port 67, which means you shouldn’t include aports:block in the file.
Heads up: If you’re running Ubuntu or Debian,systemd-resolvedoften grabs port 53 by default. If the container fails to start with a port 53 conflict, you will need to disable the stub listener in/etc/systemd/resolved.confbefore bringing Pi-hole up. Also, anyFTLCONF_variable you set here becomes read-only in the web UI, so leave the DHCP settings out of the Compose file if you want to tweak them in the browser later.
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
restart: unless-stopped
network_mode: host
environment:
TZ: "America/New_York"
FTLCONF_webserver_api_password: "your_secure_password"
# Uncomment below if port 80/443 are already used on your host
# FTLCONF_webserver_port: "8081,8444s"
volumes:
- "./etc-pihole:/etc/pihole"
cap_add:
- NET_ADMIN
- SYS_NICE
Code language: YAML (yaml)
- Replace your_secure_password with a strong password, save the file, and start the container in detached mode.
docker compose up -d
Code language: Bash (bash)
- Verify that the container is running and healthy before moving on.
docker compose ps
Code language: Bash (bash)
- Open a browser and navigate to
http://<your-host-ip>/admin(or include your custom port if you changedFTLCONF_webserver_port), then log in with the password you set.

Configuring Your Blocklists
- In the Pi-hole web interface, navigate to Lists in the left-hand menu.
- Pi-hole ships with StevenBlack’s unified hosts list enabled by default, which is a solid starting point. If you want tighter coverage against malware, phishing, and scam domains, paste your preferred blocklist URLs into the Address field, add a short note in Comment, and click Add blocklist.
Heads up: More blocklists aren’t always better. Stacking dozens of aggressive lists can break legitimate sites and streaming apps, which is a fast way to get your household mad at you. Start with one or two well-maintained lists (like StevenBlack plus a dedicated phishing/malware list) and expand only if you need to. - After adding any new lists, go to Tools > Update Gravity and click Update so Pi-hole downloads and applies the new rules.

Enabling Pi-hole’s DHCP Server
Before you flip this switch, write down your router’s current DHCP IP range and subnet mask as a back-out plan. You never want two DHCP servers fighting each other on the same network, and you want a clean way to roll back if something goes sideways.
- Log into your router’s admin page, find its LAN or DHCP Server settings, and note the starting IP, ending IP, and gateway address.
- Disable the DHCP server on your router and save the change.
- Switch back to the Pi-hole web interface and go to Settings > DHCP.
- Check the box for DHCP server enabled.
- Fill in the Range of IP addresses to hand out (From and To), making sure your Docker host’s static IP sits outside that range so Pi-hole never hands it out to another device.
- Enter your router’s IP in the Router (gateway) IP address field, then click Save.

- Test it out on a phone or laptop by toggling Wi-Fi off and back on (or running
ipconfig /renewon Windows), then check Settings > DHCP under Currently active DHCP leases to confirm Pi-hole handed out the lease.
Spinning up a Pi-hole container with DHCP enabled takes about fifteen minutes and protects every device on your network without installing a single app on your phones or TVs. Once it’s running, those fake tech support popups and sketchy ad links hit a brick wall before they even load. Give me a shout in the comments if you run into any snags getting yours up and running.