7

This is crazy, I've never has this issue until now...I like to use the hosts file to block certain websites. But for some reason my hosts file is not blocking any website. I went over this post (Hosts File not working correctly) and tried most if not all of those things but I'm still not able to use my hosts file to block websites. Anything else I can do to fix this? I've used hosts files for years and never had this issue.

Note: I just got this PC (refurbished) so maybe they created some weird settings before shipping it? I wouldn't think so but figured I'd mention it.

Here is how I have my hosts file entries...maybe I"m missing something?

127.0.0.1 localhost
127.0.0.1 website.com
127.0.0.1 www.website.com
127.0.0.1 website2.com
127.0.0.1 www.website2.com
echo
  • 93
  • 1
  • 1
  • 9

3 Answers3

9

Just changing the hosts file is not enough. You also need to flush your DNS cache.

Open a command prompt and type:

ipconfig /flushdns

Now, test if it works by pinging one of the domains, preferably one you changed recently:

ping www.website2.com

and see if it returns the 127.0.0.1

If the ping does not work, then it is likely that the permissions on the hostfile are incorrect. Incorrect permissions on the hostfile may cause an arbitrary lock on the hostsfile which prevents windows from properly read it and populating the dns cache. Fix the permissions on the hostfile then perform an ipconfig /flushdns once more.

If the ping works, but the website does not load correctly, then the website is still loading from cache. Clear your browsercache to fix the issue.

LPChip
  • 61,264
  • I ipconfig /flushdns and then pinged and it received all of the packets. It *didn't return 127.0.0.1 and instead returned the websites IP. The website loads fine in browser. – echo Dec 12 '19 at 21:12
  • So that means there's likely an issue with the permissions on the hostsfile. You can try a reboot, but ensure that the permissions are not changed and set to inherit permissions from the folder its in. By default normal users can't edit the file and need administrative permissions. – LPChip Dec 13 '19 at 07:32
  • In PowerShell use Clear-DnsClientCache. – David Clarke Jun 03 '21 at 22:54
2

Weird, there must have been something wrong with that particular hosts file, I still have no idea what it was...

I went over to: https://support.microsoft.com/en-us/help/972034/how-to-reset-the-hosts-file-back-to-the-default and followed the steps for replacing the hosts file then I manually put in my websites now it's working. Earlier, I tried to copy and paste the host file content from the above URL but that didn't work. Anyways, no more issues!

echo
  • 93
  • 1
  • 1
  • 9
0

You need to add your loopback address as primary DNS in order to be able to read from the host file.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. – Community Nov 11 '21 at 14:38