Local DNS resolution really slow on Mac OS X

I have a centos linux running as a virtual machine in a Virtual Box on my Mac OS 10.8.2. The virtual machine has the IP address 172.17.33.2. I created an entry in /etc/hosts with

172.17.33.2 centos.dev

When I try to ping the virtual machine via

ping centos.dev

it takes about 30 seconds for the first ping, after that, everything works as expected:

meckbuck2:~ mimi$ ping -n centos.dev
PING centos.dev (172.17.33.2): 56 data bytes
64 bytes from 172.17.33.2: icmp_seq=0 ttl=64 time=0.521 ms
64 bytes from 172.17.33.2: icmp_seq=1 ttl=64 time=0.294 ms
64 bytes from 172.17.33.2: icmp_seq=2 ttl=64 time=0.274 ms

If I use ping 172.17.33.2 (no DNS resolution), everything is fast and the first ping starts within fractions of a second. So it seems as something is broken with the name resolution on my computer. Can anybody give me a hint how to solve this? It is a new MacBook Retina 15" which I set up from scratch less than a week ago.

I have also tried centos.localhost as a domain name - same problem here.

Once the domain is resolved and the IP is there, everything works as expected (ssh, smb, http...). Any hint is welcome!

Edit: I used dtruss to get a dump of the syscalls when I ping the server name. The ping gets stuck at the end of the trace. You can find it here: http://pastebin.com/JXgeHsBu

Edit 2: I followed the instructions on http://blog.root-of-all-evil.com/2012/07/how-to-bypass-os-x-lions-reverse-dns-lookup-order-to-resolve-slow-local-host-lookups/ to set up a local DNS server. Still the same issue.

tcpdump gives me the following output when I start a ping on the virtual machine:

01:16:27.668409 IP 192.168.6.101.62932 > 8.8.8.8.53: 26754+ A? www.isg-apple.com.akadns.net. (46)
01:16:27.668456 IP 192.168.6.101.20149 > 8.8.8.8.53: 41456+ AAAA? www.isg-apple.com.akadns.net. (46)
01:16:27.670650 IP 8.8.8.8.53 > 192.168.6.101.62932: 26754 3/8/0 CNAME www.apple.com.edgekey.net., CNAME e3191.c.akamaiedge.net., A 23.1.61.15 (275)
01:16:27.670932 IP 8.8.8.8.53 > 192.168.6.101.20149: 41456 2/1/0 CNAME www.apple.com.edgekey.net., CNAME e3191.c.akamaiedge.net. (176)
01:16:33.178960 IP 192.168.6.101.41429 > 8.8.8.8.53: 21942+ A? e3191.c.akamaiedge.net. (40)
01:16:33.180452 IP 8.8.8.8.53 > 192.168.6.101.41429: 21942 1/8/0 A 23.1.61.15 (200)
01:16:46.876547 IP 192.168.6.101.24354 > 8.8.8.8.53: 6871+ A? 1.courier-push-apple.com.akadns.net. (53)
01:16:46.877900 IP 8.8.8.8.53 > 192.168.6.101.24354: 6871 8/10/5 A 17.149.36.102, A 17.149.36.169, A 17.149.32.52, A 17.149.36.115, A 17.149.36.178, A 17.149.36.127, A 17.149.36.181, A 17.149.36.108 (494)
01:16:53.863153 IP 192.168.6.101.61304 > 8.8.8.8.53: 32328+ A? e3191.c.akamaiedge.net. (40)
01:16:53.884441 IP 8.8.8.8.53 > 192.168.6.101.61304: 32328 1/8/0 A 23.1.61.15 (200)

Edit 3: Here is my output of scutil --dns

meckbuck2:~ mimi$ scutil --dns
DNS configuration

resolver #1
  search domain[0] : hil-allhw.phl.wayport.net
  search domain[1] : phl.wayport.net
  nameserver[0] : 127.0.0.1
  reach    : Reachable,Local Address

resolver #2
  domain   : local
  options  : mdns
  timeout  : 5
  order    : 300000

resolver #3
  domain   : 254.169.in-addr.arpa
  options  : mdns
  timeout  : 5
  order    : 300200

resolver #4
  domain   : 8.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  order    : 300400

resolver #5
  domain   : 9.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  order    : 300600

resolver #6
  domain   : a.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  order    : 300800

resolver #7
  domain   : b.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  order    : 301000

DNS configuration (for scoped queries)

resolver #1
  search domain[0] : hil-allhw.phl.wayport.net
  search domain[1] : phl.wayport.net
  nameserver[0] : 127.0.0.1
  if_index : 4 (en0)
  flags    : Scoped

reach : Reachable,Local Address


Solution 1:

I am on OSX 10.13.6 and experienced this issue for .local domains. The trick was to specify both, IPv4 and IPv6:

127.0.0.1    php.local
::1          php.local

Taken from Make .local domains NOT slow in macOS.