Google-chrome – Flush Chrome and Firefox DNS cache from command line

browser-cachecommand linednsfirefoxgoogle-chrome

Occasionally, I need to do a scorched Earth cleansing of my local DNS cachi. The most common scenario for this was that I was using OpenDNS, and when a name would fail to resolve (it was a hostname on my local network, but wasn't running), OpenDNS sends me to their lovely ad page. Then once the DNS issue is fixed, I'm still resolving to OpenDNS. That actually doesn't happen much, anymore, but still, once in a while, I just need a fresh start with my DNS.

Now, if you are likely to be able to answer my question, I'm sure you will know that modern computers hide DNS cache everywhere. Your OS has it, your browser has it, your other browser has it, if you're running DNSMasq (I am), then you have to clear that as well. So I wrote a little shell script to clear most of these caches, but the browser DNS cache still has too be done manually.

On Chrome, I go to chrome://net-internals/#dns, and click "Clear host cache"

On Firefox, I'm sure there is a similar process, I just don't know what it is.

However, I'd really like to clear both of these from the command line, so I can integrate them into my DNS-burninate script. Can this be done, and if so, how?

If Chrome or Firefox offer a command line interface to do this, that would be super cool.

If not, I assume the DNS cache is stored in a file, or set of files (is that true, or are they all stored in RAM?). If we could identify those files and delete them, perhaps that would have the same effect? Would that work, or just break everything? Where are said files?

Any other ideas?

Best Answer

Chrome/Chromium's DNS cache is all in RAM. It appears that restarting Chrome completely will inevitably clear it.

The Chromium source for host caching doesn't appear to have any committing to the hard drive for persistence. I can only assume the official Google Chrome does the same thing.


The same goes for Firefox. It appears simply restarting Firefox will clear the cache, as the code for the prefetch system doesn't suggest it commits to the hard disk either.

Related Question