
Keep Two Pi-hole v6 Servers in Sync Automatically
/ Tech, Programming, TutorialsJoin our free newsletter on Patreon for updates & behind-the-scenes →Running two Pi-holes on a home network is one of the best upgrades you can make for local DNS reliability and control. If one Raspberry Pi needs a reboot, a container updates, or a host goes offline, your second DNS server keeps the internet working for the whole house without anyone noticing.
Actually maintaining two Pi-holes, however, quickly turns into a chore.
The Pain Points of Running Two Pi-holes
Once you move from one Pi-hole to two, every small network tweak doubles in effort:
- Configuration drift: You add a Local DNS record for a new self-hosted service or whitelist a domain that broke a site, and it works on your device—until another device on your network queries the secondary Pi-hole and gets blocked or fails to resolve.
- Manual Teleporter exports and imports: Without automation, keeping adlists, groups, client assignments, and regex filters aligned means exporting a Teleporter archive from the primary and manually uploading it to the secondary every time you make a change.
- Host-specific settings collisions: You can’t just blindly copy everything from one server to another. Each Pi-hole has its own network interface, listening mode, TLS certificates, web password, and DHCP leases that shouldn’t be overwritten.
- Unnecessary FTL restarts: Older sync scripts built around Pi-hole v5 often relied on SSH keys,
rsync, or brute-force cron jobs that dumped and re-imported the entire configuration every few minutes—restarting DNS and briefly dropping queries even when nothing had actually changed.
With the release of Pi-hole v6 (FTL 6.x), Pi-hole introduced a native REST API (/api). That opened the door to solve this cleanly without SSH access, host-level scripts, or fragile workarounds.
So I built piholesync: a single static Go binary (and multi-arch Docker image) that keeps one or more secondary Pi-hole v6 servers automatically synced with a primary.
How piholesync Works
Instead of touching filesystems or requiring dependencies on your Pi-hole hosts, piholesync talks exclusively to the Pi-hole v6 REST API. That means it works identically whether your Pi-holes run bare-metal on a Raspberry Pi or inside Docker containers.
Here is what happens behind the scenes every minute (configurable):
- Smart change detection via hashing:
piholesyncreads your primary Pi-hole’s groups, adlists, allow/deny domains, regexes, client assignments, and selectedpihole.tomlsettings (by default, thednssection—upstream servers, Local DNS records, and CNAMEs). It hashes each section and compares it to what was last pushed to each secondary. - Targeted updates only:
- If gravity tables (groups, lists, domains, or clients) change, it runs a single Teleporter export from the primary and imports only those tables onto the secondary—never overwriting the secondary’s full
pihole.toml. - If adlists change (and
run_gravity: true), it triggers an Update Gravity run on the secondary. - If settings change, it compares keys one by one via
GET /api/configand sends only the differing keys withPATCH /api/config.
- If gravity tables (groups, lists, domains, or clients) change, it runs a single Teleporter export from the primary and imports only those tables onto the secondary—never overwriting the secondary’s full
- Zero false-positive restarts: A Teleporter import restarts FTL on the secondary, pausing DNS resolution for a few seconds. To avoid unnecessary restarts,
piholesyncignores counters that change on their own—like adlist domain counts, last-update timestamps, and resolved client hostnames. A scheduled weekly gravity update on your primary won’t trigger a cascade of restarts on your secondaries. - FTL restart awareness: When a Teleporter import or upstream DNS change does restart FTL on a secondary,
piholesyncwaits for the secondary to come back online before proceeding to the next step. - Drift protection: Everything syncs once at startup and again on a
full_sync_interval(default24h) to automatically undo any accidental edits made directly on a secondary.
What Intentionally Stays Separate
To keep your secondary nodes independent and safe, piholesync never syncs:
- Web interface passwords, ports, or TLS certificates
- DHCP leases
- Query logs and long-term statistics
- Host-specific keys listed under
settings.exclude(by defaultdns.interface,dns.listeningMode, anddns.reply)
Quick Start with Docker Compose
The fastest way to deploy piholesync is via Docker Compose using the multi-arch image (amd64, arm64, armv7, armv6) published to GitHub Container Registry:
mkdir piholesync && cd piholesync
curl -fsSLO https://raw.githubusercontent.com/joshuapack/piholesync/main/docker-compose.yml
curl -fsSL -o config.yaml https://raw.githubusercontent.com/joshuapack/piholesync/main/config.example.yaml
curl -fsSL -o .env https://raw.githubusercontent.com/joshuapack/piholesync/main/.env.example
Edit config.yaml with your primary and secondary Pi-hole URLs, add your passwords to .env, and start the container:
docker compose up -d
docker compose logs -f
Tip: Want to preview what will change before touching your secondary? Set
command: ["-dry-run"]in yourdocker-compose.yml, inspect the logs, and remove it once you’re ready to sync for real.
If you prefer running without Docker, precompiled static binaries for Linux (amd64, arm64, armv7, armv6) are available on the GitHub Releases page, or you can build it directly with Go 1.24+:
go build -o piholesync .
PRIMARY_PASSWORD=... SECONDARY_PASSWORD=... ./piholesync -config config.yaml -once -dry-run
Two Quick Pi-hole v6 Gotchas to Keep in Mind
If you set up piholesync with Pi-hole v6, watch out for two API permission behaviors:
- Enable
app_sudowhen using App Passwords: If you authenticate with a Pi-hole App Password instead of your main web password,webserver.api.app_sudomust be enabled on each Pi-hole. Otherwise, the API treats the session as read-only and rejects imports and config patches with a403 (read-only)error. You can toggle this under Settings → All settings → Webserver and API (in expert mode) or via environment variable in Docker:
environment:
FTLCONF_webserver_api_app_sudo: "true"
- Watch out for
FTLCONF_*environment variables: Any Pi-hole setting locked via anFTLCONF_*environment variable in Docker is read-only through the v6 API. If a locked key differs between your primary and secondary,piholesyncwill log an error naming that specific key, either match the environment variable across both containers or add the key (e.g.,dns.upstreams) tosettings.exclude.
Check It Out
Now, whenever I add a Local DNS entry or tweak a blocklist on my primary Pi-hole, my secondary picks it up within a minute—automatically, quietly, and without restarting FTL unless something actually changed.
The project is open source and available on GitHub at github.com/joshuapack/piholesync. If you’re running Pi-hole v6 in high availability, give it a spin and let me know how it works in your setup!
~Joshua
Tags: Pihole, Go, Self-hosting, Homelab, Docker, Open-source, Github, Linux, Dns, Api, Automation



Comments
Join the discussion