Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I added some domains to block ( 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.
##       localhost broadcasthost
::1             localhost
fe80::1%lo0     localhost
share|improve this question
If there is no response, Safari will try to add www. To the beginning of the URL. Facebook can then redirect the browser to Try adding 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 and * 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? – user495470 May 30 '13 at 18:37
What's interesting is that the line i use for redirecting to DuckDuckGo works, even if i put it after the redirect for, 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 '14 at 21:53

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 '14 at 11:30

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


^ Carriage Return
share|improve this answer
unfortunately this didn't help. – Nicholas Tulach Jun 3 '13 at 13:03
You have to have a newline (not a carriage return) at the end of every line, including the last one. – ganbustein Dec 23 '14 at 4:25
Unless he's running Mac OS 9. :o – William T Froggard Oct 14 '15 at 4:40

Worked for me on Yosemite:

  1. Go to System Preferences > Network > Advanced > Proxies
  2. Tick Auto Proxy Discovery, hit OK and Apply (I haven't got anything else ticked)
  3. Enter in Terminal: dscacheutil -flushcache

This flushes the dnscache in Yosemite. Now Safari and Chrome should respect your hosts file.

share|improve this answer

I had a similar issue. Every piece of software on my Mac honored my /etc/hosts file entry when my hosts file was symlinked (aliased) to another file, except Safari. When your hosts file is a symlink, Safari ignores it.

My solution was to make /etc/hosts a hard link. Luckily the hosts file I keep up to date is in the same file system. If it isn't, you're borked.

Bad Safari... bad.

share|improve this answer

According to this blog

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. – user10355 Jul 17 '13 at 14:56
They probably say to put it at the beginning to avoid a common pitfall of people editing the hosts file: they forget to put a newline at the end of the last line. Without that newline, the last line will be ignored. If you add the entry to the front, it's hard to forget the newline. – ganbustein Dec 23 '14 at 4:23
Not sure why, but this works for me. I'm using yosemite. – Vicary Jan 9 '15 at 15:23

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

share|improve this answer

I had this problem too but the solution is really easy Let's suppose you create an Alias in the host file to your machine with the name localhost2

That entry in the host file should look like this: localhost2

When you type "localhost2" in the safari url bar you will notice in the dropdown that the default option is to search that in google, you should select the option saying "Go to Site localhost2"

share|improve this answer

Your Answer


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.