Setting up two pihole instances, one as secondary local DNS

I currently run one instance of pihole that serves local DNS and it works great.

I'd like to add a second instance of pihole (on a second server) on the network to give me redundancy when I take one instance down. I'd like for one of the instances to act as a primary local DNS and the other one as secondary where it picks up local records from the first so that I don't have to define everything in both instances.

Any thoughts on ways to achieve this?

(It would be nice if everything was synced to be honest.)

Most DNS implementations dont work with primary and secondary as backup when the primary fails.
Primary and secondary are considered as just a list of DNS servers from which to choose from.
Some OS'es even dont name them primary or secondary but just DNS1, DNS2 etc.
And most of them apply some logic to determine like who is the quickest responding similar to Pi-hole's own implementation:

We keep using the fastest responding server now for 1000 queries or 10 minutes (whatever happens earlier) instead of 50 queries or 10 seconds (default values in dnsmasq).

https://docs.pi-hole.net/ftldns/dns-resolver/#improve-detection-algorithm-for-determining-the-best-forward-destination

This means your primary secondary plan will fail.

There is something called Gravity Sync if interested in having two instances synced.
But this is not supported by Pi-hole, it doesnt sync everything, and is another dependency which could break.
But I believe its quite popular.

Oh I wasn't clear.

I expect round robin DNS like normal when both servers are being handed out by DHCP.

What I'm looking for and confused about is can I manage local DNS on one instance and have it automatically propagate to a 2nd?

So if I add test.server.home on pihole1, I want it to automatically copy to pihole2 (perhaps the same way a primary/secondary DNS setup works) without having to manually enter the same record on pihole2.

What is better than a Pi-hole blocking trackers, advertisements, and other malicious domains on your network? That's right, two Pi-hole blocking all that junk on your network!

Seriously. Why two Pi-hole?

But if you have redundant Pi-hole in your network you'll want a simple way to keep the list configurations and local DNS settings identical between the two. That's where Gravity Sync comes in. Setup should only take a few minutes.

I rely on local DNS a lot including for IoT and automations (maybe I shouldn't be) so if I power down or reboot the host it can be a bit disruptive. I could probably do high availability of the LXC running pihole itself but it seemed simpler to simply have two of them running and if one goes down the other handles the requests. I'll take a look at gravity sync thanks!

And:

pi@ph5a:~ $ nc localhost 4711 <<< '>stats >quit'
[..]
dns_queries_today 6943
pi@ph5b:~ $ nc localhost 4711 <<< '>stats >quit'
[..]
dns_queries_today 2217

EDIT: And the second node (b) is a Pi 1B+ compared to node 1 (a) which is an older Pi 1B (without the +).

Yeah that's what I'm expecting.

1 Like

Its a sort of self healing mechanism if you look at it.
The clients that have the "quickest" logic will hop to another node if under circumstances node 1 is starting to lag bc of load.
Those clients will hop to another node and node 1 gets relieved again.

Sure but if second instance doesn't have the local records I'm dead in the water. It looks like gravity can do that part for me.

No.

Gravity is a set of Pi-hole functions used to update the domains contained on your adlists, in one Pi-hole instance (it runs on a cron job, at weekends). If an adlist source is updated by its developers, gravity will update your local database.

If you want 2 Pi-hole instances in sync you need to update both. You can update them manually, using a script or you can try Gravity-sync (it's a third party script).

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.