Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  cksum Dec 13 '11 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 Dec 13 '11 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 Dec 13 '11 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 Dec 13 '11 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. –  cksum Dec 13 '11 at 20:07
show 5 more comments

migrated from superuser.com Dec 13 '11 at 5:01

This question came from our site for computer enthusiasts and power users.

3 Answers

up vote 3 down vote accepted

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

share|improve this answer
    
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. –  Dave Sanders Jun 19 '13 at 14:50
add comment

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       ......
share|improve this answer
    
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 Aug 14 '13 at 18:01
add comment

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
share|improve this answer
    
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 Mar 17 '12 at 3:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.