You may be migrating a website to a new host, migrating an entire server’s worth of domains, or doing one of many tasks that requires you to temporarily change the hosts file on your computer in order to test a site that is on a new IP address.
Regardless of the reason, if you alter the hosts file and expect the changes to work immediately in Firefox 76, you may get an unpleasant surprise.
Today, I’m in the midst of testing a server migration, so I have a number of sites to test on the new, temporary IP addresses. I’m using Linux and Firefox 76, so I edited my /etc/hosts file, adding the new, temporary IP address for one of the sites, started Firefox, and browsed to the domain.
I got the old server.
What Didn’t Fix It
I tried the old, tried-and-true method of setting Firefox’s network.dnsCacheExpiration and network.dnsCacheExpirationGracePeriod to zero. That didn’t work.
I tried flushing the cache in Linux with systemd-resolve –flush-caches, but that didn’t work, either.
I tried the “Disable Cache” checkbox in Firefox Developer Tools. No joy.
Finally, I found the cause of the problem, and it comes from a relatively new feature in Firefox that is enabled by default.
DNS Over HTTPS
DNS over HTTPS was rolled out by Mozilla beginning in 2019. It’s designed to increase privacy by hiding domain name lookups from anyone lurking on public WiFi, your ISP, or anyone else on your local network.
It sounds like a really good idea to me. I had it enabled.
When I disabled DNS over HTTPS in Firefox by going Preferences -> General -> Network Settings, and clicking on the Settings button, then unchecking “Enable DNS over HTTPS” my changes to the /etc/hosts file worked.
A restart of Firefox was not required.
It Makes Sense
One of the things that led me to DNS over HTTPS was the fact that Cloudflare is the default DNS provider in the United States. I suspected that anything associated with Cloudflare had to involve some caching.