• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0

Website blocking via Hosts file

Question

+jnelsoninjax    11,380

I am trying to block a website through the Hosts file, but the site still loads, despite being supposedly redirected to 127.0.0.1. What I have done is put 127.0.0.1 domain name in the hosts file and saved it, I have verified that it is saved, but when I go to the website, it still loads, even after reboot. Am I missing something or doing something wrong? Or is it windows?

Share this post


Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 1
+BudMan    3,365

There are a bajillion things that could of been reason.

 

Didn't put entries in file correctly

saved the file with ext like .txt

didn't put in the actual fqdn of what the client was using for whatever site trying to block

didn't flush the clients local cache, or even the browsers cache - both of which are different caches

browser was using a proxy (dns and or even local host file not used then)

etc. etc. etc..

Share this post


Link to post
Share on other sites
  • 0
sagum    565
Posted (edited)
11 minutes ago, jnelsoninjax said:

I am trying to block a website through the Hosts file, but the site still loads, despite being supposedly redirected to 127.0.0.1. What I have done is put 127.0.0.1 domain name in the hosts file and saved it, I have verified that it is saved, but when I go to the website, it still loads, even after reboot. Am I missing something or doing something wrong? Or is it windows?

You need to ipconfig /flushdns

make sure your hosts file hasn't been saved as hosts.txt by mistake as well

  • Thanks 1

Share this post


Link to post
Share on other sites
  • 0
+BudMan    3,365

Who does this anymore?  Run pihole if your looking to block ###### ;)  Or block it on your dns directly with a host override?

 

Do a simple ping does it come back as 127.0.0.1?

 

Also if your browser is using a proxy, doesn't matter what you put in your host file since proxy is what resolves, not the local client.

 

But to your use of host file... Here how to test your setting is working... Keep in mind that hosts file will need admin rights to manipulate... Its also possible your running some antivirus software that prevents manipulation of the hosts file.. And yeah sagum is right, many users will save it has hosts.txt which never used.

 

 

 

 

hostfile.png

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
Robert_Leo1    0

If you are trying to block website through host files then make sure that your host's files haven't been saved with wrong names.

Share this post


Link to post
Share on other sites
  • 0
goretsky    1,003

Hello,

You need to make sure that you have entered the fully-qualified domain name (FQDN) into the hosts file.  For example, if you wanted to block https://www.example.com/ you would want to enter the following lines into the hosts file:

 

127.0.0.1 example.com
127.0.0.1 www.example.com

Note that you do not enter the protocol handler (https, http, ftp, et cetera), just the applicable hostnames.

 

Regards,

 

Aryeh Goretsky

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
+jnelsoninjax    11,380
On 4/25/2019 at 11:37 PM, goretsky said:

Hello,

You need to make sure that you have entered the fully-qualified domain name (FQDN) into the hosts file.  For example, if you wanted to block https://www.example.com/ you would want to enter the following lines into the hosts file:

 


127.0.0.1 example.com
127.0.0.1 www.example.com

Note that you do not enter the protocol handler (https, http, ftp, et cetera), just the applicable hostnames.

 

Regards,

 

Aryeh Goretsky

Thanks, I figured it out, and successfully blocked a site as a test using 0.0.0.0 instead of the 127.0.0.1

Share this post


Link to post
Share on other sites
  • 0
freqnasty    211

Did you work out why the website was still resolving when you had set it to localhost?

Share this post


Link to post
Share on other sites
  • 0
+jnelsoninjax    11,380
14 minutes ago, freqnasty said:

Did you work out why the website was still resolving when you had set it to localhost?

Never did figure that out, but I did not spend allot of time messing with it.

Share this post


Link to post
Share on other sites
  • 0
+jnelsoninjax    11,380
38 minutes ago, BudMan said:

There are a bajillion things that could of been reason.

 

Didn't put entries in file correctly

saved the file with ext like .txt

didn't put in the actual fqdn of what the client was using for whatever site trying to block

didn't flush the clients local cache, or even the browsers cache - both of which are different caches

browser was using a proxy (dns and or even local host file not used then)

etc. etc. etc..

I agree, that is why I did not spend any time to try and figure out the reason it did not work, and it was only for a test purpose anyway, I was not using it for a permanent solution.  

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.