OS X DNS lookups too slow for local hosts

networks, os x

OS can sometimes take forever to resolve hosts setup on my local machine. Here is how I solved it.

I have several local hosts set up on my dev OS X machine in my /etc/hosts file . The browser hangs for several seconds while trying to load them. Which doesn't make any sense, since they are local. The solution is to change the hosts file so that all hosts are on one line, the very first line where localhost is defined.

In other words, change from this...       localhost broadcasthost
::1             localhost
fe80::1%lo0     localhost       my-host.dev       another-host.dev       oh-that-host.dev

...to this.       localhost  my-host.dev another-host.dev oh-that-host.dev broadcasthost
::1             localhost
fe80::1%lo0     localhost

It doesn't make sense, but it works and that's all that matters. It's probably an OS X bug which at some point will be fixed.

Answer from Stack Overflow