osx - Changing hosts file in Mac OS X does not take effect

14
2014-06
  • Imran

    I have tried to alter the hosts file adding my own entries to access sites that are being blocked by my ISP.

    When address the entries as follows

    194.71.107.82   totallylegalsite.se
    

    After adding the line the changes do not take effect, I have tried in both Safari and Chrome browsers. I have tried to flush the cache via sudo dscacheutil -flushcache however this still does not make the system read the new lines. I have also tried rebooting the machine.

    EDIT:
    Strange scenario here, by pinging the IP address stated above I get the following output:

    Ping has started…
    
    PING 194.71.107.82 (194.71.107.82): 56 data bytes
    Request timeout for icmp_seq 0
    Request timeout for icmp_seq 1
    Request timeout for icmp_seq 2
    Request timeout for icmp_seq 3
    Request timeout for icmp_seq 4
    Request timeout for icmp_seq 5
    Request timeout for icmp_seq 6
    Request timeout for icmp_seq 7
    Request timeout for icmp_seq 8
    
    --- 194.71.107.82 ping statistics ---
    10 packets transmitted, 0 packets received, 100.0% packet loss
    

    However I visit the IP directly via my browser it works fine and loads the website it should.

  • Answers
    Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

    Related Question

    dns - Host file not working on Windows 7
  • Chris Haas

    Our ISP accidentally switched us from a static IP to DHCP (long story) and it might be another day or two before we get our static IP back. In the meantime I'm trying to just use a host file on my machine but I can't get it to take. I've done this a million times before but I can't seem to get it to work on my Windows 7 machine. Here's my simple one line that I'm trying to do:

    127.0.0.1        test.example.com
    

    I've added that to c:\windows\system32\drivers\etc\hosts using an elevated notepad. Then I run ipconfig /flushdns and arp -d and try pinging it with ping test.example.com but I just get:

    Ping request could not find host test.example.com. Please check the name and try again.

    If I repeat the exact same process on a virtual XP machine on the same physical machine it resolves to 127.0.0.1 which is exactly what I want.

    There's a similar post here that talks about checking the proxy settings but I don't have one configured.

    I've also checked the value of the registry key below and its set at 500 which is second lowest (class is 8):

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\ServiceProvider
    

    I also read a post that Windows 7 wants 8 spaces between the IP and the host and I tried that (as well as 7 spaces, 1 space, 1 tab) to no avail.

    I don't have time to setup a DNS server locally so that's not an option. This is all command-line, I'm not even at the browser level yet. Yes, I'm sure that c:\Windows is the correct path, I've checked %SystemRoot%. And yes, I'm sure that I'm saving the file as hosts without an extension.


  • Related Answers
  • Linker3000

    The Windows 7 hosts file can 'play up' if there are multiple spaces between the IP address and the host name - try using:

    127.0.0.1 test.example.com
    

    ...and rename the current one to hosts.bak and make up the hosts file again using notepad to make sure there's no unicode in there.

  • stevemidgley

    Are you sure that your IP stack has the hosts file enabled? I recall that by policy it could be disabled, which is a security feature. Scratch installs of Win7 have it enabled, I believe, but it's possible if you're using a corporate machine that it's been disabled and you'll need to re-enable it - I think this is done through the Network control panel as an admin.

    You sound like you're very computer literate, so don't take offense, but here is another common error:

    • Editing hosts in notepad can sometimes result in notepad saving "hosts.txt" instead -- so make sure you're editing and saving the correct file.

    I've also read that possibly restarting in safe mode and editing the file might work. This seems like hokum to me, but since I saw it in several threads, I'd pass it along.

    Finally try changing localhost in the hosts file and see if that makes any difference to be able to ping localhost? If not, then it would seem you're not messing with the right file? Or the file you're messing with is being ignored b/c your IP stack is not looking for any hosts file.. Hope this helps.