Long lookup times for .local in hosts file

3

I'm using Mac OS X 10.8.2 and I have in my local /etc/hosts this content:

127.0.0.1 dev.test.local

Together with that I locally got nginx installed to serve static files for that domain. And while it works it takes ~5 seconds before nginx gets the connection. Demonstrated by:

ba@djuproera% time curl -I http://dev.test.local/  
curl: (7) couldn't connect to host
curl -I http://dev.test.local/  0.00s user 0.00s system 0% cpu 5.010 total

What I noticed was that if I change my hosts file to this:

127.0.0.1 dev.test.com dev.test.local

I get normal sub-second responses:

ba@djuproera[master*](ruby-1.9.3)% time curl -I http://dev.test.local/
curl: (7) couldn't connect to host
curl -I http://dev.test.local/  0.00s user 0.00s system 2% cpu 0.285 total

Extra interesting is that if I switch the order of the domains in the hosts file I get slow responses again:

127.0.0.1 dev.test.local dev.test.com

Gives:

ba@djuproera[master*](ruby-1.9.3)% time curl -I http://dev.test.local/
curl: (7) couldn't connect to host
curl -I http://dev.test.local/  0.01s user 0.00s system 0% cpu 5.011 total

Do anyone have any idea what's going on here?

gaqzi

Posted 2013-01-22T08:21:54.460

Reputation: 1 058

And while curl is saying it can't connect that's just because I had disabled nginx to see if the problem was nginx or something else, as it turned out it was something else… – gaqzi – 2013-01-22T16:42:15.213

Answers

4

Seems the problem has to do with using .local:

All .local domains are technically reserved for Multicast DNS (Bonjour), 
and Lion no longer looks in /etc/hosts first when you try to lookup 
a .local domain. Instead, it asks MDNS first, waits out the 5 second 
timeout, then checks /etc/hosts.

Source: http://itand.me/mac-os-x-lion-local-domains-and-etchosts-oh-m

It's funny how defining two different domains make it work though, if the first host is made first with another TLD.

gaqzi

Posted 2013-01-22T08:21:54.460

Reputation: 1 058

That link is now dead. Try this one instead: http://en.wikipedia.org/wiki/.local.

– DaveBurns – 2014-03-05T21:23:15.507