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.

I added some domains to block (127.0.0.1 mydomain.com) to my /etc/hosts file and for some reason, Safari seems to be ignoring them. I have tried disabling Safari extensions, clearing the cache (sudo dscacheutil -flushcache), and restarting Safari and the Mac altogether. Chrome respects the /etc/hosts changes, but Safari does not. Attached is a sample of my /etc/hosts file.

I am running Safari 6.0.4 with Mountain Lion 10.8.3

Any ideas?

##
# 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       facebook.com
share|improve this question
1  
If there is no response, Safari will try to add www. To the beginning of the URL. Facebook can then redirect the browser to Facebook.com. Try adding www.facebook.com to your file and see if that works. –  JoshRagem May 30 '13 at 14:43
    
I thought this might be the case. I tried both www.facebook.com and *.facebook.com. Neither worked. –  Nicholas Tulach May 30 '13 at 15:35
    
When I saved the text in the code block as /etc/hosts, it did block Facebook in Safari. Does your /etc/hosts use CR line endings, or have you tried moving other entries above the IPv6 entries? –  ؘؘؘؘ May 30 '13 at 18:37
    
What's interesting is that the line i use for redirecting search.yahoo.com to DuckDuckGo works, even if i put it after the redirect for facebook.com, but the Facebook line doesn't do anything. Totally stumped on this one. –  Nicholas Tulach Jun 3 '13 at 12:55
    
did you flush the dns cache and clear the safary history and cache- if you don't know how to flush the dns cache you can also restart your mac. –  konqui Jun 25 at 21:53

4 Answers 4

I had this same problem and it was caused by having really long lines in my hosts file (multiple hosts mapped to the same IP address listed on the same line). I fixed it by splitting this into several lines.

share|improve this answer
    
Solved my issue, thanks! –  arnaud.breton Mar 21 at 11:30

Try putting one or two carriage returns after the last entry.

...
127.0.0.1       facebook.com

^ Carriage Return
share|improve this answer
    
unfortunately this didn't help. –  Nicholas Tulach Jun 3 '13 at 13:03

According to this blog http://thecoredump.org/2011/09/editing-the-hosts-file-in-mac-os-x-lion/

You have to put the entry at the start of the host file. Very unorthodox. Haven't any personal experience of this though.

share|improve this answer
    
They are wrong. Only syntax matters, not location. And all additional entries should always follow the defaults. –  cksum Jul 17 '13 at 14:56

I had wrong line ending. It has to have LF, I had CR.

share|improve this answer

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.