Set a second one as a second DNS server, and the clients will check it when the first pi goes down.
But, the clients might try the first one for a while, even after it dies, so suddenly “the internet got really slow” as the clients keep querying the first one first.
When that happens, the quickest thing would be to change pi2’s IP to pi1’s IP address, and when you recondition pi1, set it up as pi2…
To extend the life of the pi’s, I would suggest moving the logs to Ram:
which reduces the strain on the OS stick.
Also, if you are using pi4,
Update the firmware, and you can use a cheap, small SSD- it will last longer than a SD card, even a $5 or $10 cheap ssd, like a 60gb or small ssd (larger would work, but save less money) and a cheapish sata to USB cable (might want to look ar UASP cables if it’s gonna be used for storage too)
Basic idea is that multiple devices can negotiate with one another such that only one of them has a particular IP address. On Linux, the daemon to implement the protocol is called keepalived.
Without it, some DNS clients will pick the primary IP and wait for up to 3s for a reply before trying the secondary. That means everything slows down by 3s, until the primary DNS server comes back.
By serving a VRRP virtual IP as a DNS address instead, you’ll only have some issues until the virtual IP switches over from one host to another (few seconds) and things will be fine afterwards, the IP of the primary DNS will almost always work this way.
I like to set both as backup initially with same priority and let one of them take over, YMMV.
Test it, as a user would, if it looks fishy it’s probably broken. (e.g. I forget whether a broadcast is sent out when an IP address is assigned in order to flush out/reset various arp caches).
Note that keepalived at its simplest will be moving the IP regardless of whether there’s anything listening, so in theory you might end up with the IP stuck onto a host without DNS. This situation is strictly better than not doing keepalived at all. So for bonus points, and if you feel like this is not enough, try setting up a vrrp_script that would keep trying to resolve a DNS name, and then reference it from a track_script config stanza. Also, probably a systemdRequires= rule would already help you enough, not sure how you’ll end up starting PiHole (are you running a container or locally, are you even using systemd or sticking with open-rc).