Using a 'hosts' file

May 15, '01 06:23:31AM

Contributed by: Anonymous

The /etc/hosts file by default is ignored by OS X. Though it is possible to import hosts into the "machines" directory (see tips here on macosxhints), there is also a way to configure lookupd so it consults /etc/hosts directly.

lookupd can use different agents to lookup hosts: e.g. DNSAgent which consults DNS, FFAgent which consults local files like /etc/hosts, and CacheAgent which will keep a local cache. The trick is to tell lookupd which agents to use in which order.

Read the rest of this article if you'd like the details on making OS X use your local hosts file before it uses the DNS servers.

Here's how I did it. First open a terminal window and become root (you can also use NetInfo mgr if you prefer). type

niutil -create . /locations/lookupd/hosts [hit enter]
niutil -createprop . /locations/lookupd/hosts LookupOrder FFAgent DNSAgent [hit enter]
This means hosts are first looked up in /etc/hosts, if this fails, then DNS is used. Note I did not use the CacheAgent because my local DNS-server/router already keeps a cache.

Next you need to restart lookupd. Type
top -l|grep lookupd [enter]
to find out the PID for lookupd. Next kill the process with
kill -HUP nnnn [enter]
where nnnn is the PID. Lookupd will restart automatically.

Again, a reminder that you need to be root to do all this.

Additional info:
manpage on lookupd (type man lookupd in a terminal session)
article at Stepwise
Using NetInfo as replacement for /etc/hosts

This solved one of the biggest problems I had with integrating OS X into my network. It also seems to have solved the problem of telnet connections taking forever...

Cubist (only likes real cookies)

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20010515062331512