MacOS – Hosts file in OSX Lion not blocking as expected

macos

In Snow Leopard I blocked malware sites by editing the hosts file – /private/etc/hosts. I cannot get it to work the same way in Lion, in spite of reading up on the various issues people are reporting for Lion and hosts. For example, to block 0fees.net:

  1. sudo nano /private/etc/hosts then add 127.0.0.1 0fees.net to the beginning of the hosts file (instead of at the end, which was the usual way pre-Lion).
  2. dscacheutil -flushcache (though most authors say this is not required).

To test:

ping 0fees.net

… which then looks up the DNS and pings the host instead of returning 127.0.0.1. Rebooting seems to have no effect. How can I get blocking working again?

This is from a clean installation, not an upgrade from Snow Leopard.

Best Answer

One more thing to check - is the hosts file still in native unix format? It's quite possible within Nano to accidently save it as MSDOS or ye-olde mac format in which case it won't be parsed properly and just ignored

(This was originally an answer, but converted to a comment by a mod, and requested to be an answer again by the OP so they can accept it.)