Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a web server running on my local machine and when I perform a cURL request against it using the localhost address it executes very fast. However, when I add an /etc/hosts like

127.0.0.1 test.local

and then perform the same cURL request:

curl -I http://test.local:3002/images/logo.png

it delays for a solid 2-3 seconds. Changing the cURL request back to localhost again yields no delay.

This is reproducible every single time.

I've tried running the slow request under dtruss to see if I can find a system call that is causing the delay. Nothing out of the ordinary shows up.

I've tried making a dummy service via netcat that just returns HTTP/1.0 200 OK so I can guarantee the issue is not really due to my web server. Again, no difference: localhost is fast as you'd expect and test.local delays.

At this point I think there is somehow a DNS issue. That is, /etc/hosts is NOT being consulted first, that is, my upstream DNS is being checked, which fails, then /etc/hosts is being consulted which finally works.

Is this possible? Is OS X Lion somehow consulting my /etc/hosts later in the resolver chain?

share|improve this question

Ok, I figured it out. I found this comment on a blog post:

The matter is Lion handles .local TLD differently because it’s reserved for some Multicast DNS features (used by Bonjour). The only way i found to solve this issue is using a different TLD for development hosts (ie: .dev). It works fine for me, hope it’s gonna be helpful to others!

Switching my development domain to end in .dev works fine.

tl;dr - dont use .local for development domains in Lion.

share|improve this answer
    
You should add that if you add the IP6 line to hosts (::1 test.local), it will fix the issue. – Matt Alexander Apr 23 '14 at 19:51

OSX lion has this known bug. It would consult the DNS server first before using /etc/hosts entries. This behavior is only found in OSX lion and is not found in snow leopard, or even in tiger.

Possible options:

  • Install DNSMasq
  • Wait for patch from macosx
  • Use snow leopard for the time being

Also see http://www.justincarmony.com/blog/2011/07/27/mac-os-x-lion-etc-hosts-bugs-and-dns-resolution/ for more details. It's well covered there.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .