What's the Windows equivalent of "/etc/hosts"?

07
2014-07
  • David Faux

    Possible Duplicate:
    How do I block certain websites from being accessed through a browser?

    I can block my little brother from accessing a website on my Mac by adding the following line to my "/etc/hosts" file.

    127.0.0.1 someaddictingwebsite.com
    

    Do Windows systems have a file analogous to "/etc/hosts"? Can I achieve the same effect on a PC?

  • Answers
  • wmz

    It's normally under \WINDOWS\system32\drivers\etc (If there isn't one, just create it).
    (you have not specified OS version, win 8 monitors this file and reverts any changes, see eg. here for discussion: http://www.howtogeek.com/122404/how-to-block-websites-in-windows-8s-hosts-file/)


  • Related Question

    Possible reasons WINDOWS\system32\drivers\etc\hosts is not working (appart from the obvious)
  • rwired

    Here's my C:\WINDOWS\system32\drivers\etc\hosts file:

    127.0.0.1          localhost
    192.168.100.1      router
    

    testing it:

    C:\>ping router
    Ping request could not find host router. Please check the name and try again.
    
    C:\>ping 192.168.100.1
    
    Pinging 192.168.100.1 with 32 bytes of data:
    
    Reply from 192.168.100.1: bytes=32 time<1ms TTL=64
    Reply from 192.168.100.1: bytes=32 time<1ms TTL=64
    Reply from 192.168.100.1: bytes=32 time<1ms TTL=64
    Reply from 192.168.100.1: bytes=32 time<1ms TTL=64
    
    Ping statistics for 192.168.100.1:
        Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
        Minimum = 0ms, Maximum = 0ms, Average = 0ms
    

    It used to work. I used to have numerous redirects in there. But it stopped working a few weeks ago.

    I've checked all the obvious:

    • deleted the hosts file and replaced with this simple one just for testing
    • no invalid characters in the hosts file
    • no file extension on the hosts file
    • not using TAB to separate IP and hostname (tried using exactly 8 spaces)
    • ipconfig /flushdns
    • restart the DNS Client service
    • permissions on the file matches the permissions of the DNS Client (I've also tried "allow" for "everyone" on both the hosts file, and the "etc" folder, and also the "drivers" folder).
    • tried adding the NETWORK SERVICE user, and the LOCAL SERVICE user to this file permissions
    • no anitivirus/spamware/malware/resident shields running on this particular machine
    • tried the hosts file both with UNIX and DOS EOL markers
    • reboot the machine

    What am I missing?


  • Related Answers
  • William Hilsum

    From what you have done, and the list of things you have checked makes me think some sort of system failure as it looks like you have done the correct things, try doing "SFC /SCANNOW" from the command line just to test for system problems.

  • fencepost

    Is this a problem with the hosts file not working or is it a problem with no DNS resolution at all working on the machine (ping, IE, etc.)?

    If the latter, does nslookup work?

    If so, take a look at When DNS and ping Fail but nslookup Works on my website for the long answer.

    Short answer is that after trying all sorts of things, I ended up with "Winsock XP Fix" which someone built some years back after noting that the registry entries related to WinSock were actually the same between systems, and that sometimes they end up corrupted.

  • Maarten

    Next time, check \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath in the registry to see if the location of your hosts file is correct and the same as where Windows assumes it to be.

  • unxed

    Change hosts file owner to "Administrators" group. It fixed an issue for me.

  • Catalin DICU

    sfc /scannow didn't work for me but installing this .msi did : http://support.microsoft.com/kb/972034