OS X 10.10.1 /etc/hosts & /private/etc/hosts file is being ignored and not resolving
Solution 1:
/private/etc/hosts seems to be working normally for me in Yosemite (version 10.10.1). It's not necessary to flush the cache or reset discoveryd
(the DNS resolver in Yosemite); sudo fs_usage | grep private/etc/hosts
shows discoveryd
reading the file immediately after I save changes to it.
[Update: discoveryd
was only used in OS X versions 10.10.0 - 10.10.3. In both earlier and later versions, mDNSResponder
provides the same function... and also immediately notices changes in /etc/hosts.]
However, dig
, nslookup
, and host
will not see entries in it because they bypass the system's resolver and do raw DNS lookups. They've always done this, so this is not new in Yosemite. The "official" way to do a lookup through the system resolver in OS X is to use dscacheutil
:
dscacheutil -q host -a name www.example.com
...but since that's painfully verbose, I tend to just use ping
instead (and then look at the first line, where it lists what IP it's pinging). Starting in 10.9, you can also use Network Utility's Lookup tab (before that it used dig
, and therefore bypassed the system lookup policy).
BTW, please pay no attention to the macrumors thread that Tetsujin linked; it's full of people who don't quite know what they're doing and are misunderstanding the results of their own mistakes.
Solution 2:
I have discovered another wrinkle with this issue.
In order to fix the problem I was having, I had to ADD IPv6 style hosts file entries.
It seems that Safari will overlook IPv4 entries IF you have an IPv6 network configuration setup.
You must add duplicate entries that resolve to IPv6 localhost address in /etc/hosts.
IPv4 entry
127.68.56.101 facebook.com
e.g. IPv6 entry
fe80::1%lo0 facebook.com
etc.