Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Using a 'hosts' file Network
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)
  • Currently 3.67 / 5
  You rated: 4 / 5 (3 votes cast)

Using a 'hosts' file | 7 comments | Create New Account
Click here to return to the 'Using a 'hosts' file' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Why do this?
Authored by: babbage on May 15, '01 11:17:11AM
I plead naivete -- it seems to me that the main benefits of this would be [a] managing a local network
and [b] providing caching/backup for DNS. I know there are better reasons, but I'm
mostly unaware of them.

The main reason I use the hosts file on my NT box (what? BSD-ness on NT? Ye gods! And
yet there it is -- C:WINNTsystem32driversetcHOSTS -- and I didn't even put it there) is as a sort
of junkbuster-esque banner ad filter. Basically, if you map any known ad server to the localhost
address (, you are effectively piping it to /dev/null.

Sweet. Not what it's there for, I'm sure, but very nice all the same.

Here's my NT hosts file. It's the same format as it would be on any other system, so you should be
able to use it on OSX or *nix or whatever else you like (OS9? Not sure...).

# Copyright (c) 1993-1995 Microsoft  Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows NT.
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a "#" symbol.
# For example:
# # source server
# # x client host localhost
... ... ..
[NOTE: long list of hosts deleted; email babbage directly (by clicking on the linked username) if
you'd like a copy of the whole file].

You get the idea. Any site you want to filter out, just add a line like
"", and you'll never see it on a web page again, nicely replaced by
(if you're running a local webserver) an easily ignored "404 not found" page.

[ Reply to This | # ]
CDDB/freedb and ad blocking tricks
Authored by: j-beda on May 15, '01 04:22:44PM
What I would like to do is modify the way iTunes (and other programs) access the database of song titles. There are instructions for doing so in OS 9.1 by playing with the hosts, but no instructions for OS X, here: There are unix style hosts files for this CD trick that I will now be able to try with Mac OS X. A list of ad domains for hosts files is maintained at:

[ Reply to This | # ]
Even better hosts ad blocker file
Authored by: Jay on Sep 18, '01 01:01:11AM
Go to It's huge! Every ad site I could think of and a LOT more.

[ Reply to This | # ]
Authored by: cedmond on Jul 25, '02 10:02:13AM

I tried this (obviously the wrong way) and completely hosed my system, requiring a complete reinstall of everything.

If you try mucking with the NetInfo database in anyway, especially from the command line, I strongly recommend backing it up first!

Instructions on how to do so are here.

[ Reply to This | # ]
Using a 'hosts' file
Authored by: alajuela on Feb 23, '04 09:09:29AM

Is it still necessary under 10.3 to force OS X to look up hosts in the hosts file? I.e., does the system still use the DNS Agent first?

[ Reply to This | # ]
Using a 'hosts' file
Authored by: ghay on Mar 01, '07 12:11:49PM

I don't think you are correct, I've never seen an OSX mac disrespect the hosts file.

I always lookupd -flushcache after changing it, but adding an entry to any of my 10.3 boxes or 10.4 boxes ping entries in /etc/hosts just fine.

[ Reply to This | # ]
Using a 'hosts' file
Authored by: aschmidtm on Mar 02, '07 09:45:31AM

I've been using the hosts file since 10.2 at the very least (I think 10.1 to be honest) and never had any problem resolving from hosts. Maybe I'm just lucky.


[ Reply to This | # ]