3

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.

10
  • Two things. 1) did you try www.0fees.net? It might be getting stuck on the leading "0." 2) if all your doing is blocking traffic, use 0.0.0.0 instead of calling for a loopback. 127.0.0.1 is more resource intensive than using 0.0.0.0 (which just kills the connection rather than loopin it back home). Also put the line at the end not the beginning. The first lines should always be reserved for the system entries.
    – user10355
    Commented Dec 13, 2011 at 5:13
  • 1
    Yes, I tried www.0fees.net (and several other blocked domains in the list) and they're not blocked. Also, in Lion all additional entries to the HOSTS file must be above the fe80::1%lo0 localhostline.
    – Simbamangu
    Commented Dec 13, 2011 at 9:01
  • 1
    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.
    – Garry
    Commented Dec 13, 2011 at 14:07
  • 2
    @Simbamangu Your assertion about hosts entries must be above the localhost line is absolutely false. I have several custom entries, all below the f380::1%lo0 localhost line, and they work fine.
    – Cajunluke
    Commented Dec 13, 2011 at 17:34
  • As I said, add your entries to the end. Like @CajunLuke said above, I have several entries and they work just fine.
    – user10355
    Commented Dec 13, 2011 at 20:07

3 Answers 3

3

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.)

1
  • oh.my.god. I've been looking for this answer for days. For some reason my file was set as mac format and completely ignored. Resaving as unix format worked. Commented Jun 19, 2013 at 14:50
0

In Lion, the entries must be below the the fe80::1%lo0 localhost line. Works for me.

The first entries are reserved for the System. Then, you can make your own entries.

Just like that:

    ##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost

# Block any ip
127.0.0.1       ......
1
  • Are you sure about the Lion part? I tried putting them below the fe80::1%lo0 localhost line, didn't work, but keeping them above did it. Running Lion. There's a comment to the original post with the same experience.
    – Erika
    Commented Aug 14, 2013 at 18:01
0

Is your system fully updated and are you running any third party software? Maybe you have a VM with network kernel drivers or something? Have you tried on a clean install of OS X?

It works for me on OS X 10.7.3:

ma:~$ sudo nano /private/etc/hosts
Password:


GNU nano 2.0.6                        File: /private/etc/hosts                                                        

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##

127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost

127.0.0.1 0fees.net



ma:~$ dscacheutil -flushcache
ma:~$ ping 0fees.net
PING 0fees.net (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.045 ms
1
  • Hi @Abhi Beckert - apologies, there's a long comment thread above where we got a solution (non-unix hosts file format) but it wasn't put in as an answer yet. Thanks though!
    – Simbamangu
    Commented Mar 17, 2012 at 3:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .