Is there a way to resolve domains via DNS (cloud) first, and check (permanent) local cache or local storage if they upstream DNS server is unreachable?
I am using Pi-Hole as my DNS server, and I am looking for a solution for a problem for resolving a particular domain.
I have my own domain under Cloudflare DNS. This domain is used for my home network, and for Dynamic DNS to be able to access from outside the network. Like this (about 20-30 different subdomains):
external-subdomain.domain.commay direct to my external IP updated to be kept in sync.
internal-subdomain.domain.commay direct to a static internal IP.
Usually Pi-hole resolves fine to Cloudflare DNS and everything works fine.
Today, internet went down. Pi-hole lost access to the internet, and to the upstream DNS server. While a lot of my
internal-subdomain.domain.com are internal IPs, all these links broke because the DNS couldn't be resolved because Pi-hole didn't have internet.
I am looking for a way to solve this problem in the future.
I have been thinking on what could be some ways to resolve this, but I am unsure what would be the best way or if I am missing some ideas. Any input is appreciated.
The way I solved this today was by creating Local DNS for all the
internal-subdomain.domain.com and that solved it. This works, but I would like something dynamic, as I may add new subdomains or change existing ones, and I do not want to have to input it on both Cloudflare and Pi-hole. If I only update one of them, it may go out of sync and create issues.
One option would be to only look at the Local DNS if the upstream DNS is unavailable. I am not sure if this is a configuration that exists, or makes sense. It also doesn't solve the problem of having to manually maintain both systems in sync. However, at least it would only be a "situation" when internet goes down.
Ideally, I would love that Pi-hole uses the normal upstream DNS and resolves the IP normally. I would like this to be stored in local cache, and used any time when internet is down. Ideally, some sort of "permanent" cache.
Caching does this, but it doesn't in the wrong order. What I mean is that if cache exists, Pi-hole would hit the local cache first (rather than upstream DNS first, local as a backup); until it expires. This may lead to wrong resolution if I have updated the IPs on Cloudflare and ttl is long. On the other hand, if I reduce the ttl, I might find myself in a situation where I cannot resolve it because cache is gone.
Additionally, this only works if I had access that domain before.
Another option would be having a system that syncs everyday the DNS from Cloudflare to the Pi-hole. Cloudflare has an API, so downloading this would be straightforward. However, I am not sure if Pi-hole as a way to dynamically add, remove and/or update the Local DNS using API, cli or writing to a file. Any way I could achieve this?
Are there any other or simpler solutions to solve this problem?
Thanks for your help and time in advance!