Lion takes long to connect to local server

Does your /etc/hosts file look like this?

[code lang=”bash”]127.0.0.1 gladlycode.local gladlycast.local
127.0.0.1 babyessentials.local kw.sg.local
127.0.0.1 localhost[/code]

Every request I made to gladlyCode.local takes 5 seconds to resolve to my local Apache server. Something was wrong!

If it does and you’re on Mac OS X Lion, you should change your VirtualHost names to something else. It turns out that Mac OS X Lion no longer looks up /etc/hosts first when you try to lookup a .local domain since are technically reserved for Multicast DNS (MDNS), or Bonjour. Starting Lion, it will lookup through MDNS first, and after the 5 second timeout, it checks with /etc/hosts.

This is at a cost of developer productivity and I have to change all my .local domains to .internal.kw.sg which is a domain name I own. I figured that if it is a domain name I own, it will never clash unknowingly. I changed ‘gladlycode.local’ into ‘gladlycode.internal.kw.sg’ and point it to 127.0.0.1 now. Now testing gladlyCode no longer takes 5 seconds per request (ridiculous!).

Alternatively you can use another top level domain (TLD) instead of .local and the common ones such as .com.

2 thoughts on “Lion takes long to connect to local server”

  1. You don’t need to use a “real” TLD if your just making local development hosts. Use something “gladlycode.lan” or “gladlycode.dev” to bypass the .local issue.

  2. @Tony, that’s true. The advantage of using a domain I own is I know there definitely wouldn’t be another gladlycode.dev TLD introduced in future which could clash in future.

Leave a Reply

Your email address will not be published. Required fields are marked *