Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Why I Run 2 Pi-hole Instances & How I Keep Them Synced

· 6 min read · Home Tech

In this article
  1. Background: Why One Pi-hole Isn’t Enough
  2. How Pi-hole Works Under the Hood
  3. How I Keep the Two Instances Synced
  4. What to Sync and What Not to Sync
  5. Common Problems and How to Avoid Them
  6. Costs and Hardware Considerations
  7. Alternatives to Two Pi-holes
  8. Frequently Asked Questions

I run two Pi-hole instances on my home network to eliminate a single point of failure for DNS and ad blocking, and I keep them synced using a combination of Gravity Sync, a cron job, and a shared configuration directory. This setup ensures that if one Raspberry Pi (or VM) goes down, the other automatically handles all DNS queries, and both devices always have identical blocklists and settings.

Background: Why One Pi-hole Isn’t Enough

Pi-hole is a network-wide ad blocker that acts as a DNS sinkhole. It intercepts DNS queries from all devices on your LAN and blocks requests to known advertising and tracking domains. Most home users run a single instance on a Raspberry Pi, which works fine until that device fails, needs a reboot, or you’re doing maintenance. When that happens, every device on your network loses DNS resolution — meaning no internet at all, not just ads.

Running two instances gives you redundancy. If one goes offline, the other handles all queries. It also lets you perform updates or reboot one Pi without disrupting your family’s streaming, gaming, or work calls. The trade-off is that you now have two separate databases of blocklists, settings, and whitelists that can drift apart. That’s where syncing comes in.

How Pi-hole Works Under the Hood

Pi-hole uses dnsmasq as its DNS forwarder and a SQLite database (called gravity.db) to store the blocklist domains and client/group settings. When you update the blocklists, Pi-hole downloads lists from sources like StevenBlack’s hosts file or Firebog’s lists, processes them, and stores the domains in the database. The web interface (accessible at http://pi.hole/admin) lets you manage whitelists, blacklists, DHCP, and per-client settings.

Because everything is stored in that SQLite database, syncing two instances essentially means keeping those databases identical. But you can’t just copy the file while Pi-hole is running — SQLite doesn’t handle concurrent writes well, and you’ll risk corruption. The standard approach is to use a tool like Gravity Sync, which handles the transfer safely.

How I Keep the Two Instances Synced

My setup uses two Raspberry Pi 4s, each running the latest Raspberry Pi OS Lite and Pi-hole. One is the primary, the other is the secondary. I use Gravity Sync to copy the database and configuration from the primary to the secondary. Here’s the step-by-step process I follow:

  1. Install Pi-hole on both devices using the standard one-line installer (curl -sSL https://install.pi-hole.net | bash).
  2. Set a static IP for each Pi on your router, and configure your router’s DHCP to hand out both IPs as DNS servers (so clients use the primary first, then the secondary).
  3. Install Gravity Sync on the secondary Pi by cloning the repository and running the install script. The script will ask for the primary Pi’s IP and SSH credentials.
  4. Run ./gravity-sync.sh on the secondary to perform an initial sync. This copies the gravity.db file and the setupVars.conf (which holds settings like the admin password and DNS upstreams) from the primary.
  5. Add a cron job on the secondary to run ./gravity-sync.sh every hour. I use crontab -e and add: 0 * * * * cd /home/pi/gravity-sync && ./gravity-sync.sh.

That’s it. Every hour, the secondary pulls the latest database from the primary. If you make a change on the primary (like whitelisting a domain), it will propagate to the secondary within the hour. If you want faster sync, you can run the script manually after changes, or set up a more frequent cron job (e.g., every 5 minutes).

What to Sync and What Not to Sync

Gravity Sync copies the core database and the main settings file, but not everything. For example, it does not sync the DHCP leases file, because that’s unique to each device. It also doesn’t sync the local DNS records (if you use Pi-hole as a local DNS server for hostnames), because those might be device-specific. In my setup, I only use Pi-hole for ad blocking and don’t rely on its DHCP server, so syncing the database and settings is sufficient.

If you use Pi-hole’s DHCP server, you should only run it on one instance to avoid IP conflicts. The secondary should have DHCP disabled. Similarly, if you use conditional forwarding (to forward local domain queries to your router), you’ll need to configure that on both instances manually, as Gravity Sync doesn’t handle it.

Common Problems and How to Avoid Them

  • Database corruption: Never copy gravity.db while Pi-hole is running. Gravity Sync uses a lock file and copies to a temporary location, but if you manually copy, stop Pi-hole first.
  • SSH key issues: Gravity Sync uses SSH to connect to the primary. If you change the primary’s IP or SSH port, you’ll need to update the sync script’s configuration.
  • Sync failures after Pi-hole updates: Pi-hole updates can change the database schema. After updating either Pi, run ./gravity-sync.sh manually to ensure compatibility. If it fails, you may need to re-run the Gravity Sync install script.
  • Both instances going down: If both Pis lose power, you have no DNS. Consider adding a third DNS server (like your router) as a fallback, or use a UPS for the Pis.

Costs and Hardware Considerations

Running two Pi-holes doesn’t require high-end hardware. A Raspberry Pi Zero 2 W is sufficient for most home networks (it handles DNS queries easily), but I use Pi 4s because they have more RAM and faster storage, which helps when updating large blocklists. The cost is roughly $35 per Pi (plus SD card and power supply), so about $70 total. If you already have an old PC or a NAS, you can run Pi-hole in Docker containers instead of buying new hardware.

Power consumption is minimal — each Pi 4 draws about 3-4 watts under load, so the yearly electricity cost is under $5 per Pi in most regions. The main cost is your time in setting up and maintaining the sync.

Alternatives to Two Pi-holes

If running two Pis seems overkill, you have other options:

  • Run Pi-hole on a single device with a fallback DNS: Configure your router to use a public DNS (like 1.1.1.1) as a secondary, so if the Pi fails, clients still get DNS (but no ad blocking). This is cheap but not seamless.
  • Use a cloud-based ad blocker: Services like NextDNS or Control D offer similar functionality without hardware, but they require a subscription for full features and send your DNS queries to a third party.
  • Run Pi-hole in Docker on a NAS: If you have a NAS, you can run two containers on the same device, but that still has a single point of failure (the NAS). Better to run one on the NAS and one on a Pi.

Frequently Asked Questions

Do I need two Pi-holes if my router already has DNS?

Your router’s DNS doesn’t block ads. Pi-hole does. If you only care about ad blocking and can tolerate occasional downtime, one Pi-hole is fine. Two is for redundancy.

Can I sync Pi-hole instances without Gravity Sync?

Yes, you can manually copy the gravity.db and setupVars.conf files using scp or rsync, but you must stop Pi-hole first. Gravity Sync automates this and handles locking, making it safer.

Will syncing overwrite my secondary’s whitelist?

Yes, Gravity Sync makes the secondary identical to the primary. If you add a whitelist entry on the secondary, it will be overwritten on the next sync. Always make changes on the primary.

How long does a sync take?

Typically under a minute for a home network with a few hundred thousand blocked domains. The script compares checksums and only transfers if the database changed.

What happens if the primary is offline when the sync runs?

The sync script will fail gracefully and log an error. The secondary will keep using its last synced database, so it still works. Once the primary is back, the next sync will succeed.