How does firefox cache DNS requests/replies?

I was wondering how, if it all, does firefox cache say, google.com to its respective IP?


Solution 1:

It caches it short-term, but I don't know the particulars of the backend. You can see this when DNS doesn't resolve, and you use the refresh button only to find you quickly land on the Server Not Found page again; but, if you click the "Try Again" button on that page, it re-queries the DNS server. Or, if you close and reopen Firefox, the cache will have cleared.

I've found this out through pure experimentation; I've been doing quite a bit of DNS settings changes lately.

This article claims that "In Firefox, by default, the DNS requests are cached for only 1 minute." but it is dated August 2007, so things may have changed by now. (see below)

To control the cache settings, you might try the DNS Cache extension or the Clear Dns Cache extension.

You can also tweak the about:config setting network.dnsCacheExpiration to manually set the cache time; its default is 60 seconds, confirming the above article. Or network.dnsCacheEntries controls the maximum number of cache entries. You will likely need to add these settings to the about:config page yourself (New > Integer), and setting either one (or both) to 0 should disable the cache.

Solution 2:

In the end of 2008 (released in 2009) Mozilla implemented DNS prefetching or pre-resolution in Firefox 3.1 (3.5), the discussion and code changes are available at bugzilla's bug 453403. Since then the defaults are network.dnsCacheExpiration equal to 180 seconds and network.dnsCacheEntries equal to 400 entries. This ensures more cache hits, especially useful when DNS prefetching is enabled. Previous values were 60 and 20, respectively. Check your settings in about:config and if these two have old values update them for better performance.

A look at Firefox's code reveals that network.dnsCacheExpiration is converted to minutes as an integer, so for instance every value in the range 120-179 for this setting equals 2 minutes of TTL. Negative records are cached for exactly 1 minute (not configurable; hardcoded).

If you perform a request for a domain which has been negatively cached Firefox displays the Server not found page with the "Try again" button. At the same time an attempt to resolve the domain again is performed in the background. That's why when there has been just a short problem clicking on the "Try again" button opens the site immediately.