Removing an entry from /etc/hosts on a Mac

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 has been replaced with dscacheutil:

$ dscacheutil -flushcache

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

I love feedback and questions — please get in touch on Twitter or leave a comment.