Setting up multiple DNS servers

I have Pi-Hole deployed on one of the machines on the LAN, but it sometimes may get unresponsive, so I need a fail-proof setup here as follows - I need a list of DNS servers, where the top element has the highest priority, so the next element is applied only if the previous is down, like so: Pi-Hole (highest priority) -> dynamic DNSs from ISP (I have 2 WANs with MWAN3, pppoe and mobile) -> -> (lowest priority).

Is it possible, and if so, how do I do it the right way?

I think this page should help, I am not sure but I think you may be limited to 4 DNS servers not sure where I read that.

As far as prioritizing DNS servers the clients will not respect any priority and use all the DNS servers whenever they want seemly random although they will prefer the fastest.

Dnsmasq has a setting to to use servers in a strict order, This page should give you all the commands that is available to dnsmasq.

[OpenWrt Wiki] DNS and DHCP examples
[OpenWrt Wiki] DNS and DHCP configuration /etc/config/dhcp

I would try following:

uci add_list dhcp.lan.dhcp_option="3,<dns1>"
uci add_list dhcp.lan.dhcp_option="3,<dns2>"
uci commit dhcp
/etc/init.d/dnsmasq restart

I'm afraid that ordered DNS is too slow to be considered a viable approach.
While using it, DNS queries need to timeout before proceeding to the next resolver.

DNS doesn't work that way, what exactly happens is client specific, but in general implies using the DNS servers in a round-robin fashion, without any ordering or priority. The only viable option if any of your DNS servers isn't reliable, would be not to use it at all.

1 Like