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

Strange behavior of /etc/hosts

We had to redo the IPs of some of the static machines in the house here after I went to 10.6, and I had set some static entries in /etc/hosts on my MBP so I could just type "ssh user@machine" on the command prompt, rather than an IP. It worked great in Leopard, but now I'm seeing a weird phenomenon. When I edit the file it works fine now, but when I reboot it erases the change and I have to go and swap the IP again for that host (from 192... to 10...). Very annoying -- what is possibly causing this?

13" MacBook Pro, Mac OS X (10.6.2)

Posted on Jan 8, 2010 7:57 PM

Reply
23 replies

Jan 10, 2010 8:19 AM in response to LittleSaint

LittleSaint wrote:
It's not a Directory Services problem.


It is not a "problem" at all.

I add records to /etc/hosts on all of my Macs, and have never had to modify Directory Services.


Are all your Macs configured identically to that of the original poster? Of course they aren't. Clearly something is different about your machines. Just saying "it works for me" is not a solution. I have given the original poster two clear-cut solutions and some things to look at to try to figure out exactly what is happening with /etc/hosts, if so desired.

Jan 10, 2010 8:31 AM in response to LittleSaint

LittleSaint wrote:
The OP has a legitimate question about something that should and does work just fine under Mac OS X


That is clearly an illogical statement. Yes, the original poster has a legitimate question. But if it really did "work just fine" then why would the original poster even be asking?

so far you've offered absolutely nothing to help solve it.


Complaining about me isn't helping anyone.

Moreover, you really need to do some research on host files, DNS, and DHCP before commenting anymore.


No, I don't, because I don't care. If someone wants to learn about exactly how MacOS X handles name lookups, by all means they should. Personally, I don't want to bother with it. That's why I suggest an easy solution with DHCP and Bonjour.

It's only making you look bad.


I'm not here to look pretty.

Jan 10, 2010 9:21 AM in response to mcs37

The permissions on /etc/hosts appear to be 644 (ownership is root.wheel) There is a @ after the permission which I've never seen before on other *nix systems:

-rw-r--r--@ 1 root wheel 341B Jan 8 18:28 hosts

After editing the file everything works fine until reboot and worked fine indefinitely under Leopard, so I'm thinking something changed in Snow Leopard.

I'd be happy to use whatever the preferred solution is, I'm just used to editing /etc/hosts since I deal with Linux every week.

What is the preferred solution in 10.6 for adding static IP entries to my local host database?

Jan 10, 2010 12:36 PM in response to mcs37

mcs37 wrote:
I'd be happy to use whatever the preferred solution is, I'm just used to editing /etc/hosts since I deal with Linux every week.

What is the preferred solution in 10.6 for adding static IP entries to my local host database?


On all of our machines, editing /etc/hosts does the trick. There must be something different about the configuration of your machine. If I run "dscacheutil -configuration", I get:

DirectoryService Cache search policy:
/Local/Default
/BSD/local

What do you get? I suspect the first line is going to say something more interesting than mine. The idea is that you can store your local DNS entries in the network database for all machines instead of having to add them to each machine one at a time.

Now, I don't have a real network, so I'm well within the realm of pure speculation in this matter. I suspect that is the cause and I suspect that if you edit the network hosts settings via dscl you will fix the problem for all machines. If, however, that doesn't work, you can still use dscl to add those entries into your local DNS table instead of /etc/hosts. You can script that and have launchd reset it every time you boot up. That isn't an ideal solution, but it should work. I do something similar with my VPN connection.

Jan 19, 2010 4:57 AM in response to BobHarris

DHCP in large organizations tends to fall apart under stress. Static IP's minimize dependence on the
org's infrastructure and simplify troubleshooting or reconfiguration when there are problems.

For small to medium outfits, Bonjour, Apple's implementation of zeroconf <http://zeroconf.org/> is dead simple and (contrary to OP's impression) works very well in mixed environments. Recent linux distros use the avahi implementation <avahi.org>.

Strange behavior of /etc/hosts

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