Working with /etc/hosts on Mac

apple

Creating hosts file entries allows you to create DNS aliases which can be very handy for web development. If your on a Mac, you will notice that it has the /etc/hosts file just like other unix os's.

One problem I kept running into however was that OS X was caching my host entries. So if I added a line like this:

192.168.0.80 dev.example.com

And then I changed it to this:

127.0.0.1 dev.example.com

The dev.example.com host will still resolve to the old IP address.

Flushing the DNS Cache on Mac

If you are running Mac OSX Leopard (10.5) or greater, you use the dscacheutil command to flush the dns cache, eg:

dscacheutil -flushcache

If you are using an earlier version of Mac OSX, for example 10.4, then you need to use the lookupd command:

lookupd -flushcache

cfobjective pre-conf training

Related Entries

This entry was:

WAF for CF

Trackbacks

Trackback Address: 685/ACDFEB51C6F3F4F8A03D0A4B730571C4

Comments

On 10/01/2009 at 1:48:00 PM EDT Larry wrote:
1
Great tip. Except that even with a dscacheutil refresh and a reboot I'm still seeing sites blocked because of the hosts file, after it'd been edited to not block anything. Not sure what to do...

Post a Comment




  



Spell Checker by Foundeo

Recent Entries





Basecamp
pfreitag on twitter