Fixing Slow Hosts File Lookups in OS X Mountain Lion

Mac users with custom entries in their /etc/hosts files may have noticed that, under Mountain Lion at least, lookup times for local resources are incredibly slow. I routinely set up names that point to virtual hosts on my laptop so I can give projects their own local domain instead of having http://localhost/projects/something/index.php or somesuch. Typing is much easier. I noticed that, since upgrading from Snow Leopard to Mountain Lion, Firefox would spend several seconds trying to look up those names before consulting the hosts file and loading the page.

While I don’t know why it’s happening, exactly, I do have a fix. The wait goes away if you put the local entries on one line.

Instead of having something like this:

#virtual hosts

You need to have this:

#virtual hosts

Leave the lines that say “localhost” alone, of course. Messing with those could cause all manner of Bad Things.

  • John

    It does help, also UNIX-like line termination helps:
    hope it works for you