Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Chrome from caching a site's DNS records

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?

like image 674
Petrus Theron Avatar asked Dec 01 '10 07:12

Petrus Theron


2 Answers

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.

like image 187
Scott Avatar answered Oct 21 '22 02:10

Scott


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.

like image 35
jorlow Avatar answered Oct 21 '22 04:10

jorlow