← LAB NOTEBOOK · REPORT LN-2611-10 · HOW-TO · DNS · ● VERIFIED
Two Pi-holes with failover that actually works
A shared address, two health checks, and one step most guides skip: making sure your clients actually use the shared address.
RESULT
Stopping DNS on the primary moves the shared address to the backup with about 4 seconds of failed lookups, and it moves back cleanly. Every client now asks the shared address instead of one server.
Two of anything is one, and one is none. Everybody in this business has heard that. What nobody says out loud is the sequel: two of something wired up wrong is still one, it just costs more electricity.
My lab has two Pi-hole servers sharing one virtual address. On paper that’s been true for a long time. This month I went through it properly, and found two different ways it was less redundant than it looked. The first one, a health check that never ran, got its own write-up. This post is the whole setup as it stands now, including the second problem, which was sneakier.
The shape of it
- Two Pi-holes on different hardware. One is a container on my virtualization cluster. The other is a VM on a separate hypervisor. If one platform has a bad day, the other one doesn’t care.
- One virtual address that clients use for DNS, say
192.0.2.250. keepalived moves it between the two using VRRP. I use unicast between the two peers rather than multicast. - Priorities 10 and 9. The primary normally holds the address.
- Each Pi-hole uses public resolvers for itself, not the virtual address. A DNS server that needs itself to start is a puzzle you don’t want at 2 a.m. (At my house, 2 a.m. is already taken: it belongs to a newborn and a feeding.)
Check what matters, locally
The health check runs on each box and answers one question: is this Pi-hole doing its job? It doesn’t touch the internet, so an internet outage can’t fail both servers at once.
#!/bin/bash
# Healthy = answers a local record AND blocks a known ad domain.
dig @127.0.0.1 nas.example.internal +short +time=1 +tries=1 | grep -qx '192.0.2.20' || exit 1
dig @127.0.0.1 ads.example.com +short +time=1 +tries=1 | grep -qx '0.0.0.0' || exit 1
exit 0
The second check asks a different question: can this box still reach the LAN? It pings three things that are almost never all down at once, so one device rebooting doesn’t trigger a failover.
#!/bin/bash
for ip in 192.0.2.254 192.0.2.200 192.0.2.201; do
ping -c1 -W1 -q "$ip" >/dev/null 2>&1 && exit 0
done
exit 1
Wire the checks in
Here’s the keepalived side. The parts people miss are script_user with enable_script_security, and the track_script block inside the instance. Without track_script, the checks are defined and never run.
global_defs {
script_user root
enable_script_security
}
vrrp_script chk_pihole {
script "/usr/local/bin/pihole-health.sh"
interval 2
timeout 4
fall 2
rise 2
weight -4
}
vrrp_script chk_lan {
script "/usr/local/bin/lan-reach.sh"
interval 5
timeout 4
fall 2
rise 2
weight -4
}
vrrp_instance DNS {
# state, interface, priority 10 (backup: 9),
# unicast peers and auth as you already have them
track_script {
chk_pihole
chk_lan
}
virtual_ipaddress {
192.0.2.250
}
}
The weights are the clever-sounding part, so here’s the arithmetic. A failing check lowers a box’s priority by 4. If the primary fails, it drops from 10 to 6, below the backup’s 9, and the address moves. If both boxes fail the same check, they drop to 6 and 5, and the primary still holds the address. Something answering beats nothing answering.
Test the config before you restart anything: keepalived --config-test.
The step most guides skip
This was my second problem. When I mapped who was actually using which resolver, the containers that get their settings from DHCP were using the shared address. Good. But my cluster hosts and a couple of containers had the primary Pi-hole’s own address typed in.
Which means for them, there was no failover at all. If the primary went down, the address would move and they’d keep asking the empty chair.
So I repointed everything to the shared address: the hosts’ DNS settings, and the containers with a static nameserver. I kept a backup of each resolv.conf before changing it. Afterwards, nothing in the lab referenced the primary’s own address for DNS. Only the Pi-holes themselves still use public resolvers, as above.
If you take one thing from this post, take this: list every client and what it actually uses. Redundancy that a client bypasses is decoration.
Test the failure you care about
Rebooting the primary is the easy test, and it passes even with a broken setup. The real test is the DNS service dying while the box stays up. I stopped Pi-hole’s DNS service on the primary for 13 seconds and watched:
- The address moved to the backup.
- Clients saw about 4 seconds of failed lookups.
- When I started the service again, the address moved back cleanly.
Keep the two in step
Failover only helps if the backup knows the same things as the primary: the same local records, the same blocklists. I sync the two every 15 minutes. That’s a post of its own: keeping two Pi-hole v6 servers in sync.
Small print
keepalived also logged a warning that its default script user didn’t exist. It was cosmetic, but the global_defs block above makes it go away, and it means the scripts run as a user I chose rather than one I guessed.
Two of anything is one. Two of anything that you’ve actually unplugged on purpose is two.
Names and addresses are placeholders · first published November 2026