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.
- 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) …
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.
127.0.0.1 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 …)
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 …)
entry and flush your DNS again.