Secondary DNS server in use only when main is off?

Is there an option to set a primary / secondary DNS?
I have a Pi-hole device and I set the router to use it. It works great, but when I had to take it down for some time, my PC’s had problems connecting the internet.

I wish that the Pi-hole will be used as DNS server all the time and have another DNS server that will be used only if the pi-hole is not working.

Currently I have my DNS set this way:
Network -> interfaces -> WAN -> Advanced Settings ->
Deselect “use DNS servers advertised by peer”
Use custom DNS servers = my Pi-hole IP.

How can I do this? Is there a way to know which DNS server is in use?
I saw that there is allot of information about the DNS in the user guide, but I have a very minimal knowledge about networking and could not make any sense of it.

as far as I know there's not a way to enforce "failover". When your router advertises DNS to the LAN, each LAN client discovers a number of DNS addresses... it's then up to them how they use it. One operating system may request from the first one, wait, and then fail over to the second one, but other operating systems will just send queries in parallel to all of them and take whatever comes back first

The easiest way is probably to just log into the router and change what is used on the WAN during the maintenance period for the PiHole

1 Like

You could experiment a bit with the "strict order" and "all servers" options in dhcp advanced configuration.

-o, --strict-order
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 in /etc/resolv.conf
--all-servers
By default, when dnsmasq has more than one upstream server available, it will send queries to just one server. Setting this flag forces dnsmasq to send all queries to all available servers. The reply from the server which answers first will be returned to the original requester.

You should assign the nameservers under the interface they are reachable from, so pihole should be assigned to lan.
However in this case I would clear those settings and use the servers option in dhcp.

-S, --local, --server=[/[]/[domain/]][[#]][@|[#]]
Specify IP address of upstream servers directly. Setting this flag does not suppress reading of /etc/resolv.conf, use --no-resolv to do that.

2 Likes

There was a similar thread where we discovered that using strict order will result in a permanent significant delay when the first resolver is down.

A possible solution can be a connectivity watchdog script, switching resolvers depending on the status of the host.

3 Likes