Tag Archive for 'mac-os-x'


Managing DNS and the hosts file on your Mac OS X system

Subtitle: Working with /etc/hosts and lookupd for Mac OS X

If you are a developer looking to test web sites on your Mac or maybe you have different DNS for different locations (office, home, client, airport, etc…), you may need to temporarily override the authoratative DNS for a host.


First, open up the /etc/hosts file as root. In a Terminal (Applications > Utilities > Terminal) …

% sudo vi /etc/hosts

Then go to to the bottom of the file and make an entry. The format is IP, followed by whitespace (tabs are nice) and then a list of space-separated domains. Don’t forget the “www” version if you need it.

# IP Address  Host   yahoo.com www.yahoo.com

Then, voila, your computer will think that site is found at the IP you specified.

What? Didn’t work? You need to clear your DNS cache:

(For Mac OS 10.4 …)

% lookupd -flushcache

Later, when you’re done fooling your machine, do the same thing again and just comment out or delete your

(For Mac OS 10.5 …)

% dscacheutil -flushcache

entry and flush your DNS again.