10

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?

Petrus Theron
  • 25,051
  • 30
  • 137
  • 263

3 Answers3

8

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. After going there click the Clear host cache button.

Edit As noted in an answer below, the reason this doesn't immediately take effect is that you also need to flush the open sockets. After clearing DNS cache, also go to: chrome://net-internals/#sockets and click on the Flush socket pools buttons.

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.

Scott
  • 763
  • 1
  • 6
  • 14
  • Thanks for pointing to this page. I had actually set my host names to point to IPv6 because it was easier to type 127.0.0.1, but I failed to realize that chrome didn't have IPv6 on (this page showed me that). Immediately after clearing host cache and turning on IPv6 things worked great. – Kevin Peno May 28 '13 at 22:50
  • Oddly, this doesn't work for me. If I change my hosts file and click the button to clear, it still uses the cached host, even though no cached hosts are listed in the table any longer. – Dan Jan 29 '14 at 21:29
  • Ah I forgot there might still be an OS-level cache. I'm on Linux and I don't believe the OS does any DNS caching, but windows and mac does. For windows it would be `ipconfig /flushdns` and for mac it would be `sudo dscacheutil -flushcache` – Scott Feb 12 '14 at 15:30
4

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.

jorlow
  • 613
  • 6
  • 13
  • 3
    Thanks. I read somewhere that the Chromium project has a `Shift+F5` function that forces a DNS refresh, but this still has to make its way into Chrome itself. – Petrus Theron Dec 06 '10 at 10:37
2

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

Matteo Conta
  • 1,343
  • 11
  • 16