Where is the Pihole DNS cache and how do I clear it?

Expected Behaviour:

Upstream DNS should dictate the IP address for a domain name. At the very least, records should be updated periodically or when records are flushed and system is rebooted.

Actual Behaviour:

Pihole is seemingly storing DNS records for a long time, writing them to a file somewhere, and not updating with new DNS information even after reboot.

A while ago, I configured a static IP address, name resolution, on my Pihole to point a name to an IP address. Let's just say "my.server.com" was pointed to "1.2.3.4". Since then I moved "my.server.com" to "1.2.3.5". However, Pihole is apparently still resolving as "1.2.3.4" and after flushing tables, restarting dns, flushing, restarting Pihole, shutting down power, restarting Pihole, I cannot get it to resolve as "1.2.3.5". I now have no reference, no static ip configured, and still it's returning "1.2.3.4". I cannot find anywhere in the UI where the old IP is stored. From other systems, if I use nslookup, they all say they are getting the IP from Pihole.

So, I understand that the DNS cache is in RAM, but through reboots and power cycles, it's clear that there is a file somewhere that also has this cache. Where is that file?

1 Like

If you rebooted your Pi-hole host machine, it isn't a caching issue.
The cache is memory only, it doesn't survive reboots or even Pi-hole restarts.

How exactly did you do that?

And please share such an unexpectedly wrong resolution, by providing the output for the following command, run from a client in your network.

nslookup my.server.com

Substitute my.server.com with the actual hostname.
Please provide the full output, including the exact command that you ran.

There is a place somewhere in Pihole where you can make it a DHCP server as well, and create static resolutions. I haven't had that configured in a very long time. And that's why I was really surprised to see my old IP address. More surprised when all my attempts and reboots, and it still persisted.
nslookup yields:
Server: 127.0.0.1
Address: 127.0.0.1#53
Name: my.server.com
Address: 1.2.3.4

Is Pi-hole's DHCP server currently enabled?
Is that device at 1.2.3.4 still acquiring its DHCP lease through Pi-hole?

Please upload a debug log and post just the token that is generated after the log is uploaded by running the following command from the Pi-hole host terminal:

pihole -d

or do it through the Web interface:

Tools > Generate Debug Log

Have you checked the local hosts files on the Pi? Pi-hole can use these for local name resolution.

Configured in a config file in /etc/dnsmasq.d/
/etc/hosts
/etc/pihole/local.list
/etc/pihole/custom.list

Thank you so much, very helpful!

So, the old system is referenced/defined in the /etc/hosts file. Before I change it, where is this file managed by the GUI. I know I've never revised the file manually, but I've poked through every part of the GUI (I think), and see it no where. Best guess is it is a leftover piece of when I did have DCHP configured (which isn't now, and hasn't been configured in a while)

It isn't - Pi-hole doesn't alter /etc/hosts, it just reads it.
You have added those lines yourself at some time in the past.

In the future, when you want to add a local DNS record, you may use Local DNS Records for that.

Thanks. Something modified it. I'm aware of only the DHCP static items and DNS items as you noted. Till jfb pointed me to those files, I wasn't even aware of where to look.

If I had to guess, it was the "Static DHCP leases configuration" because I did use that GUI long ago. However, it isn't listed in the GUI in either the DHCP or DNS settings.

Pi-hole does not modify the /etc/hosts file on the host platform. This must have been done either manually or by other software. In any event, it sounds like your problem is resolved.

Yes, it's fixed now and thanks again.

Since you guys are saying Pihole doesn't modify the /etc/hosts file, I'm curious how or what modified it. Should I be concerned? Pihole is the only service running on a Raspberry Pi, which is used for nothing else. Besides the static ip and name that I'm 100% sure I set from within the GUI, there were other items seemingly related to Pihole in the /etc/hosts file. Now that I've removed the problem one, this is what remains:

127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

127.0.1.1 pihole

Does that all look correct?

Yes.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.