With Windows 7, why is an entry in the hosts file not working?

3

1

I updated some entries in the hosts file at C:\WINDOWS\System32\drivers\etc. As a test, I decided to make Google point to 127.0.0.1.

# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

127.0.0.1       localhost
::1             localhost
127.0.0.1       google.com

This works fine on Windows Vista, but not on Widows 7. When I type google.com into my browser, it goes directly to Google's website.

I am not using a proxy server, and I think there might be some temporary DNS settings that need to be flushed, but I'm not sure.

Does anyone know how to fix this?

user3864

Posted 2009-09-27T16:04:17.297

Reputation:

Just out of curiosity, why are you doing so ? – Sathyajith Bhat – 2009-09-27T16:13:12.443

to show that pseudo-hackers that post videos proving they hacked a website is not true always :) – None – 2009-09-27T16:57:57.173

this is why I did this :) http://www.martani.net/2009/09/bloginycom-is-hacked-google-too-video.html

– None – 2009-09-27T23:10:23.833

What browser are you using, might be good to say. Goes right to my local apache2.4 here with FireFox on win 7. – Elliptical view – 2014-01-26T02:40:57.347

Answers

6

You may have to restart Internet Explorer or Firefox, or whatever browser you are using.

Also, try going to command prompt and typing:

ipconfig /flushdns

Lastly, double check you are typing google.com in the address bar and remember that both google.com and www.google.com are completely different as far as DNS is concerned and you will need to add an entry for both.

William Hilsum

Posted 2009-09-27T16:04:17.297

Reputation: 111 572

2very common misconception about the www. I've see SO many sites forget to set domain.com to forward to their web server leaving ONLY www.domain.com working or visa versa. :) – Jeff F. – 2011-01-14T15:35:03.487

1

I noticed it takes a certain amount of time to resolve on windows 7.

Also I only have one space separating "127.0.0.1 domain" and it works fine.

ipconfig /flushdns doesn't seem to make a difference just clear your cache and wait a few minutes it will eventually take effect.

if still have problems make sure you running notepad as admin when you edit file and saving.

idkwhattoputhere

Posted 2009-09-27T16:04:17.297

Reputation: 11

The number or type (tab) of spaces between 127.0.0.1 and domain does not matter, at least on my win 7 box. – Elliptical view – 2014-01-26T02:33:52.237

1

Here is what i did, when that all above solutions failed. go to: C:\Windows\winsxs Search for "hosts" for me it is located at: C:\Windows\winsxs\x86_microsoft-windows-w..nfrastructure-other_31bf3856ad364e35_6.1.7600.16385_none_045b589158ae90da\hosts

right-click it>> properties>> security>> advance>> owner tab change ownership to administrators, next change permissions of the file to full control to administrators group.

Edit the hosts file with the entries.

Disable chrome's dns pre-fetching as it could cache ip addresses of many sites. Also check your internet settings and disable any proxy servers you are using.

Lervzc

Posted 2009-09-27T16:04:17.297

Reputation: 11

This is a terrible idea. Never touch the WinSxS folder. I would also be very surprised if a hosts file there would be effective. – Daniel B – 2016-10-19T12:49:04.807

1

An addition to @wil's answer.

the spaces between the IP and the host name is so important under windows 7

127.0.0.1       localhost

Under vista, a tab works perfectly, but under windows 7, it seems that it must be 8 spaces

user3864

Posted 2009-09-27T16:04:17.297

Reputation:

1This is not accurate. I'm on Windows 7 Home Premium 64bit. I don't have time to test for tab or other number of spaces, but I have entries that work with 6, 7 and 8 spaces. – JannieT – 2012-02-24T10:09:58.340

To be honest, I haven't really messed around with hosts file since moving to 7, (do it all at the DNS server). Good advice if accurate - +1 – William Hilsum – 2009-09-27T17:13:23.867

Unix requires any whitespace to be present. While not very surprising, Windows moving away from that format is kinda unusual. (I haven't tried Win7 myself.) – user1686 – 2009-09-27T17:50:52.883

-1 because the number of spaces does not matter. You can also use tabs. At least that's how my win 7 box works. – Elliptical view – 2014-01-26T02:34:52.540

0

Your entry was correct but somehow I did some of experiments on myself. So what I did was to clear my browsing history from the beginning of my browser eg: Google Chrome, after I cleared out all of the history I closed the browser and re-launched it again and try to browse the website that you want to block.

(But make sure you edit or put already the entries of websites that you want block in the HOSTS file)

At first I edit the HOSTS file and block the website that I want then after that I open my browser without clearing its browsing history and thats it its not working hehe.

Anonimoz xD

Posted 2009-09-27T16:04:17.297

Reputation: 1

0

This is an old question but just today we had a situation where we noticed the host file being ignored. My answer is probably not applicable to the lot of you, but if I can help only one person from pulling out their hair, it was worth posting it.

In our case, we used notepad++ to edit the hosts file and couldn't figure out why none of the entries worked. Turned out notepad++ was saving the file with a wrong EOL (end of line) format. When we eventually opened the file in normal notepad, we saw one huge string on line 1. So it did nothing.

Gerben Rampaart

Posted 2009-09-27T16:04:17.297

Reputation: 101

1Notepad++ displays the line ending type in its status bar, by the way. You can also convert it. – Daniel B – 2016-10-19T12:49:50.353

@DanielB, you're correct. It wasn't notepad++'s shortcoming I was trying to point out but rather prevent someone from having the same oversight. – Gerben Rampaart – 2016-10-19T20:05:57.953

-1

I think i just figured out why it does not seem to be working if you choose to test it with google and that is because our browsers change the address to https and as its a secure protocol it bypasses our trusted host file. but in fact its still working fine. As an example now obviously blocking hp.com is only as a test please undo after you confirm its working try adding 127.0.0.1 www.hp.com dont worry about how many spaces as long as there is one it should block that address

Richard Lalaz

Posted 2009-09-27T16:04:17.297

Reputation: 1