Question

Chrome caches DNS records and tends to ignore changes to the hosts file after it has successfully connected to my site (barring a restart). With DNS pre-fetching enabled, it is even more pronounced.

Are there any page headers that will instruct Chrome not to cache a site's DNS? Like Cache-Control or a response status like 307 Temporary Redirect?

Was it helpful?

Solution

This is probably a real bug in Google Chrome. I created http://crbug.com/65570 to track it, but please add any additional information you can think of to the bug so we're sure we understand your problem correctly.

It sounds as though the only work-around besides closing Chrome is unplugging the network cable and then plugging it back in. When Chrome sees such an event, it drops its socket and dns cache. The correct solution for the bug is likely to do the same when we see /etc/hosts has changed.

If you'd like to know when the bug is fixed, go to http://crbug.com/65570 and click the star next to the bug number. And, like I said, please add any additional information you can to the bug.

OTHER TIPS

I'm not sure if this is exactly what you're looking for, but this annoys me too switching dev environments, and I stumbled across this internal chrome page that lets you clear the cache by the click of a button: chrome://net-internals/#dns

Then click clear host cache. It's not automatic, but hey it's something.

Also keep in mind the operating system might do its own level of caching. Linux doesn't cache dns entries I think (at least for me clearing the chrome cache is good enough), but for windows or mac you might need to flush the OS-level DNS cache as well. Run ipconfig /flushdns from command line for windows or sudo dscacheutil -flushcache from command line for mac.

In my case I often switch from my dev web server and a production server using custom hosts files, in order to clear all the dns cached info from chrome I use this procedure, and it works instantly in the same tab where I need to load the updated web site address:

  1. Copy and paste this url in chrome: chrome://net-internals/#dns
  2. Click on the "Clear Host Cache" button and also click on the small black arrow in the top right corner of the window, click "Clear cache" and "Flusk Sockets", and the new address will be loaded istantly.

Chrome Dns panel

I don't have anything really to add except that this really kills me for web development since I modify /etc/hosts to reach my dev environment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top