ruby, rails, textmate, automation, etc.

Removing an entry from /etc/hosts on a Mac

Posted on June 09, 2008

I was testing a freshly deployed web site for a client the other day before they’d setup their DNS entry, and added the server to my Mac’s /etc/hosts file. It looked something like this:

208.75.85.73    www.clientsite.com

When I’d finished my testing I removed the entry from /etc/hosts. On most Unix systems that’s enough to eradicate all traces of your meddling, but not on the Mac. Any IP address that you add to /etc/hosts gets cached by the operating system.

After a bit of poking around I discovered lookupd. On Tiger you can flush the cache by entering this in the terminal:

lookupd -flushcache

On Leopard the lookupd command appears to have been replaced with dscacheutil. I’ve not had to clear my cache on Leopard yet, so whether it works in quite the same way remains to be seen.

Update: The HostsWidget Dashboard widget appears to solve the same problem rather well.

Post a comment
Comment