0

I'm specifying certain domains in my hosts file to block them. So redirecting a domain to 127.0.0.1 when i'm not running any web server on 127.0.0.1 will block that domain.

why does it take chrome two minutes to pick up that a domain has been blocked in the hosts file, and can that time be decreased a lot?

If I go to rice.com then it loads. (I used rice.com just as a test)

I then tried these lines in my hosts file to block the website from loading

127.0.0.1 rice.com
127.0.0.1 www.rice.com

Immediately after saving the hosts file, I go to rice.com in chrome, and it still loads.

But if once rice.com has loaded, I leave it for two minutes, as it is, then I try to reload it, then it says "rice.com refused to connect." So chrome finally picks up that the domain is blocked.

If I then edit the hosts file to unblock that domain, by commenting those lines, then chrome picks up immediately that it has been unblocked and goes there. So, for unblocking chrome is very responsive. (understandable, since if chrome can't load it I imagine it does everything to try to load it and part of that is checking the hosts file).

I tested this on Windows 7 and on Windows 10, same thing. (Apart from one of my tests on Windows 10 where it responded immediately picking up on a block. But other than that one time, Windows 10 seems to take a while to pick it up, but picked it up after 2 minutes, as Windows 7 does).

I have tried ipconfig /flushdns but I haven't noticed it making any difference

I'm wondering if there is any setting related to that two-minute delay and any way to decrease it?

Note- Somebody commented asking re Firefox. I tested on Firefox and firefox is worse. I had rice.com blocked in the hosts file and firefox saw that. Then I unblocked it. Chrome picks up immediately that it's unblocked, but firefox even after two minutes hadn't figured it out. Firefox took 4 minutes to notice that rice.com was unblocoked while chrome notices immediately. As for the other way, so, once a site loads, then the site is blocked, how long it takes chrome to realise is 2 minutes. How long it firefox to realise, well i've given firefox over 4 minutes before a refresh and it still hasn't figured it out

barlop
  • 23,380
  • 43
  • 145
  • 225
  • How about other browsers? Same problem? What was different about the test with the short response time? – Albin Apr 30 '22 at 19:16
  • @Albin firefox is pretty bad.. I had rice.com blocked in the hosts file and firefox saw that. Then I unblocked it. Chrome picks up immediately that it's unblocked, but firefox even after two minutes hadn't figured it out. Firefox took 4 minutes to notice that rice.com was unblocoked while chrome notices immediately. As for the other way, so, once a site loads, then the site is blocked, how long it takes chrome to realise is 2 minutes. How long it firefox to realise, well i've given firefox over 4 minutes before a refresh and it still hasn't figured it out. – barlop Apr 30 '22 at 19:35
  • I updated my answer, please give it a try. – Albin Apr 30 '22 at 19:46

1 Answers1

0

A few things to clear up first: The browser doesn't check the hosts file, the operating system does. Note (in case you don't already know) that you don't "block" a URL by adding it to the hosts file, you just specified the IP to your local machine which doesn't run the (any) webserver.

So if Chrome still connects to the website it means the website's IP is still cashed somewhere, even if it's gone from the machine's DNS cache. You probably need to clear the browser cache as well via chrome://net-internals/#dns, that will hopefully solve the problem. You can test this by pinging the URL after you entered it into your hosts file (the change should be immediate, if not, flush the OSs DNS cache ipconfig /flushdns, if it doesn't help the browser isn't the issue).

If the browser seems to remain the issue, try to reload the page bypassing the cache, or open the URL in an incognito tab that should bypass the cache as well.

Albin
  • 9,307
  • 11
  • 50
  • 89
  • regarding your suggestion in a previous edit to try running a web server I ran into an issue there https://superuser.com/questions/1718787/web-browsers-are-not-picking-up-my-web-server-via-the-hosts-file-but-they-pick – barlop Apr 30 '22 at 19:51
  • @barlop Forget my earlier version, I misunderstood your question earlier... but it might be a clue nonetheless, but try the ping test first and flushing the browsers DNS cache – Albin Apr 30 '22 at 19:55
  • The ping test does verify that the hosts file has changed. So I think clearing the DNS record the browser has is the thing. But, i'm not sure how to flush/clear the DNS cache in chrome and firefox.. You mention re chrome, going to chrome://net-internals/#dns and there there's a button that says "clear host cache". That button doesn't seem to do anything. – barlop Apr 30 '22 at 20:20
  • @barlop In FF you can use `about:networking#dns` you can clear as well as view the cache, not sure about chrome [here might be a hint](chrome://net-internals/#dns). In addition to FF try to use a fresh browser instance version, e.g. via a portable version that hasn't cashed the site yet, see if the problem persists. – Albin May 01 '22 at 06:17
  • @barlop note, that I failed to recreate the problem using current Chrome Version 101.0.4951.41 and FF 99.0.1 – Albin May 01 '22 at 06:22
  • the words are cache and cached(not cash and cashed).. If I go to about:networking#dns it shows a list of hostnames, including rice.com , it associates it with 127.0.0.1 even while it goes to the rice.com website. and even if i have a web server running locally. When I click the button to clear DNS cache it doesn't seem to change that list, the list still shows rice.com and associated with 127.0.0.1 – barlop May 01 '22 at 06:26
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/135958/discussion-between-barlop-and-albin). – barlop May 01 '22 at 06:27
  • @barlop see addition to my answer: the third paragraph (I also answered your question in the chat) – Albin May 02 '22 at 09:54