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 authoritative DNS for a host.


  • Do you have root? If you’ve never enabled root, try Apple’s page on enabling root
  • Do you have the IP of the host you want to override?

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.

Caxy Interactive is a Custom Software Development Company

See what other services Caxy has to offer.