You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

/etc/hosts file not being used in Snow Leopard

I have added several hosts to my /etc/hosts file in Snow Leopard. In Leopard (10.5), once I saved the /etc/hosts file, the hosts were available and usable. In Snow Leopard, it's like this file is never read or used. I cannot get Snow Leopard to use these entries at all in Terminal. I use this "local DNS" style feature every day at work to connect to computer systems on the corporate LAN.

In past releases, you had to import these entries into NetInfo; however, as of Leopard, my understanding is that NetInfo is gone (or, at least, niload is).

Am I missing a new step in Snow Leopard? I have tried logging out and back in, and I've restarted the computer many times since the entries were made.

Any help would be much appreciated.

MacBook Pro Core 2 Duo, 2.66GHz, 4GB RAM, 320GB HDD, Mac OS X (10.6.1)

Posted on Sep 16, 2009 10:24 AM

Reply
Question marked as Top-ranking reply

Posted on Sep 16, 2009 10:33 AM

/etc/hosts works fine in snow leopard. make sure you use the correct syntax when editing it and also make sure that it has correct permissions. it should be owned by the system and have 644 permissions.
24 replies

Sep 16, 2009 11:57 AM in response to V.K.

V.K. wrote:
/etc/hosts works fine in snow leopard. make sure you use the correct syntax when editing it and also make sure that it has correct permissions. it should be owned by the system and have 644 permissions.


Well, don't I feel stupid... I had switched the order of the entries to "name<tab>IP address" rather than "IP address<tab>name". 😟

Thanks for making me double-check. I only work in Unix every day... 🙂

Sep 16, 2009 1:02 PM in response to Sharp-man

Sharp-man wrote:
V.K. wrote:
/etc/hosts works fine in snow leopard. make sure you use the correct syntax when editing it and also make sure that it has correct permissions. it should be owned by the system and have 644 permissions.


Well, don't I feel stupid... I had switched the order of the entries to "name<tab>IP address" rather than "IP address<tab>name". 😟

don't feel too bad. I for one also have to double-check the order of the fields in /etc/hosts every time I edit it (which is not very often).
Thanks for making me double-check. I only work in Unix every day... 🙂

Sep 28, 2009 12:57 PM in response to V.K.

Hello,
well I have the same problem even with the correct syntax. I put this inside:

127.0.0.1 facebook.com


but the name still gets resolved

~ $ host facebook.com
facebook.com has address 69.63.184.142
facebook.com has address 69.63.176.140
facebook.com mail is handled by 10 mx.sf2p.tfbnw.net.
facebook.com mail is handled by 10 mx.snc1.tfbnw.net.


Any ideas ?

Sep 29, 2009 1:56 AM in response to Tex-Twil

Sorry, I didn't notice you were using the host command.

Utilities that directly use the DNS resolver like dig, host and nslookup never use local files.

But if you try to visit facebook.com with Safari, you won't be able to get there.

For example, try this after placing your entry in /etc/hosts:

dscacheutil -q host -a name facebook.com

From the man page for host(1):

Mac OS X NOTICE
The host command does not use the host name and address resolution or
the DNS query routing mechanisms used by other processes running on Mac
OS X. The results of name or address queries printed by host may
differ from those found by other processes that use the Mac OS X native
name and address resolution mechanisms. The results of DNS queries may
also differ from queries that use the Mac OS X DNS routing library.

Sep 30, 2009 3:10 AM in response to Tex-Twil

I'm not sure how you're typing "facebook.com", but if I add this line to /etc/hosts:

<pre>127.0.0.1 facebook.com</pre>

then do a:

dscacheutil -flushcache

I can no longer reach facebook.com, getting an error stating Safari cannot contact facebook.com.

However, the problem is that after doing that you can still access www.facebook.com.

I'm also assuming you have "Configure IPv6" set to "off" in your network interface's "Advanced-TCP/IP" tab.

Oct 19, 2009 12:46 PM in response to Dogcow-Moof

Okay, so here's the odd part -> if I make the domain I'm trying to fool 127.0.0.1, it works as advertised. As soon as I try to make it some other address, it fails.

For example:

/etc/hosts
127.0.0.1 localhost somedomain.com

then

sudo dscacheutil -flushcache

Safari sees the /etc/hosts value.

/etc/hosts
192.168.1.99 somedomain.com

then

sudo dscacheutil -flushcache

Safari does not see the /etc/hosts value.

/etc/hosts file not being used in Snow Leopard

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.