MAMP Pro slow name resolving with .local vhosts in Lion (fix)

An issue I’ve encountered with MAMP Pro since having upgraded to OS X Lion was that requests to vhosts served via MAMP took their time to load: after about 3 to 5 seconds of loading, the site would finally load.

The most tricky part in this issue is that it only happens if you have a domain ending in .local, such as mysite.local. If you’d rename the site to mysite.dev, it’d be — … beware, buzzword coming up … — snappy again.

Turns out, after a few Google Search Coupons, that the culprit is Bonjour (emphasis mine):

The Multicast DNS feature of Bonjour technology allows devices on a local network to connect to each other by name without a separate DNS server. By default, any hostname ending in .local is treated as a Bonjour host rather than by querying the DNS server entries in Network preferences.

Though the .local domain is not defined as a valid top-level domain on the Internet, some private networks have DNS servers that assign hostnames in the .local domain. By default Mac OS X does not use the DNS server to resolve these names. This may result in unexpected failures to connect to .local hostnames defined by your server.

To fix this problem (without having to rename each vhost) you need to add IPv6 entries for each of your vhosts in your /etc/hosts file:

::1 mysite.local
fe80::1%lo0 mysite.local
127.0.0.1 mysite.local

After that, .local vhosts load fast again. I’ve created an issue on the MAMP bug tracker for this, requesting the author to automatically add IPv6 entries to the hosts file when creating/editing a vhost. Hope to see this fixed in a future version. For now, the fix above will have to do.

Note that after restarting MAMP, the IPv6 entries will be gone … yeah, so that bug needs to fixed soon (either by Apple, or by MAMP). If you don’t want all the hassle after a restart, you might consider renaming your vhosts to .dev (anything but .local will do) UPDATE 2011.12.18: If you tab-delimit the vhosts (a rather unknown trick) for the ::1 entry, MAMP won’t delete it when reloading MAMP/adding a new vhost. Eventually, your hosts file will look like something this:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1	localhost	mysite.local	myothersite.local	anothersite.local	yetanothersite.local
fe80::1%lo0	localhost

127.0.0.1 mysite.local
127.0.0.1 myothersite.local
127.0.0.1 anothersite.local
127.0.0.1 yetanothersite.local
Did this help you out? Like what you see?
Consider donating.

I don’t run ads on my blog nor do I do this for profit. A donation however would always put a smile on my face though. Thanks!

☕️ Buy me a Coffee ($3)