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

14
2014-06
  • Questioner

    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?

  • Answers
  • William Hilsum

    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.

  • idkwhattoputhere

    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

  • Lervzc

    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.

  • Seasoned Advice (cooking)

    win 7 firewall control common domain name and does not override them with your hosts file.

    so that localhost works, instead google.com no.

    so just disable windows firewall service, and restart pc.

    bye


  • Related Question

    dns - Windows 7 etc/hosts file broken?
  • ssc

    I have a local webserver running that I would like access as myserver.localhost, so I added an entry

    127.0.0.1       myserver.localhost
    

    to C:\Windows\System32\drivers\etc\hosts. This worked fine.

    Then something happened. Among others, I had to disable Windows User Access Control, but I doubt that that is the cause. Now the system does not react to changes in the hosts file anymore. I commented out the entry, added new test entries, flushed the DNS cache several times, rebooted the machine, went for a break, nothing helps.

    nslookup still returns 127.0.0.1 for myserver.localhost and non-existing domain for any test entries I add. To me it seems the file itself is broken in some way (it's just a text file, but anyway...) and Windows fails to work with it and therefore just returns whatever it thinks was the last good result.

    Does anyone have an idea how to get back to a working hosts file without re-installing the entire system ?


  • Related Answers
  • lg.

    How did you edit the hosts file? Maybe the editor added an extension (.txt) to the file! Check from dos prompt (dir C:\Windows\System32\drivers\etc\hosts*).

  • nhinkle

    There is a general misunderstanding about how the HOSTS file in Windows and the nslookup tool interact. The value that you enter in the HOSTS file is what gets used by the system when you establish a connection to whatever domain name you might specify. This is essentially hard-coded by you entering it in the HOSTS file. However, nslookup ignores the HOSTS file for anything other than localhost. Try this: add an entry to your HOSTS file, and save the file. Do an nslookup: it should return the real IP address (or none if the real address doesn't exist). Now ping the host. It should ping the IP that you specified in the HOSTS file.

    I don't know the exact reason for this behavior, but I believe it may be that nslookup always does a DNS query, and for anything at *.localhost, it asks the local machine what the address is (hence you get the result from the HOSTS file), but for anything else, it asks the DNS server which you have configured. This part is just speculation, but the actual behavior I described is something I've observed many times.

  • Aaron Digulla

    Changes to etc\hosts are picked up instantly. If that doesn't work, then you're either editing the wrong file (say you're working remote and accidentally picked the wrong server for the SMB mount) or a virus is interfering. Check that the virus scanner is up to date and check your whole system. Try a second virus scanner just to be safe.

  • Andreas Rehm

    You need to edit this file as administrator. Otherwise you can't change it.

    Just press the start button - enter cmd in the search input box, right click on cmd and run it as administrator. Enter notepad and Open the file again, make your edits and save.

    This is the way you need to use in Windows 7.

  • ssc

    Unfortunately, there is no solution to this problem and no explainable reason for the cause. Something broke the file and the only way to fix it seems to be a complete re-installation of the entire system. We have abandoned on Windows as a development platform and moved to Mac and Linux.