Failover rather than round-robin DNS servers

I don't know if the following is possible, maybe if not, it might be a config option to consider:

I run a split DNS, the DNS server within my network serves up private addresses.
It runs on 10.0.0.4.

I have configured pi-hole with its first DNS server as 10.0.0.4
I added a second server (8.8.8.8) as fail-over, to cover the case where 10.0.0.4 became unavailable.

Unfortunately, this isn't working as I expected. Pi-hole appears to round-robin between the first and second configured DNS servers.

Is there a way to configure it to use failover rather than round-robin?

dnsmasq is the software that controls the dns forwarding aspects of pi-hole.

what you want to do is go to /etc/dnsmasq.d/ and add a new configuration file (editing the others will be temporary as they will be rewritten by pihole). name the new file 05-philippeake.conf, to indicate that its your custom config file.

in there, add the following:

strict-order

From the dnsmasq manual page: "By default, dnsmasq will send queries to any of the upstream servers it knows about and tries to favour servers that are known to be up. Setting this flag forces dnsmasq to try each query with each server strictly in the order they appear."

then use the command "pihole restartdns"

This sounds like exactly what I want.
Thanks!

With the config files, I assume that they are read in order (01-, 02- etc)
and that any redefined configuration options in later files take precedence?

yes i believe that's how it works.

One oddity with this.

For whatever reason, it takes the second IP address (the Alternate) one as the "primary".
So if you want a specific DNS server as "primary" with failover to the alternate, remember to swap the DNS servers in the setup.

My setupVars.conf file looks like this:

DNSMASQ_LISTENING=single
DNS_FQDN_REQUIRED=false
DNS_BOGUS_PRIV=false
DNSSEC=false
PIHOLE_INTERFACE=wlan0
IPV4_ADDRESS=10.0.0.21/24
IPV6_ADDRESS=
PIHOLE_DNS_1=4.2.2.2
PIHOLE_DNS_2=10.0.0.4
QUERY_LOGGING=true
INSTALL_WEB=true

All requests are going to 10.0.0.4 (which is what I want).

1 Like