After upgrading to Mac OSX Lion I figured out that /etc/hosts is not looked up in first place for name resolution anymore. This leads to some side effects like:
Is this behavior intended? Does it make any sense? And most important, how can I come back to the old behavior.
Access your command prompt. Use the command nslookup (this stands for Name Server Lookup) followed by the domain name or IP address you want to trace. Press enter. This command will simply query the Name Service for information about the specified IP address or domain name.
Locate and open Terminal from Applications->Utilities->Terminal. At the Terminal Prompt, type ifconfig and press Enter. This will list all of your network settings, including the physical addresses of your wired and wireless hardware. Write down or copy/paste the addresses into a document for future reference.
I think he 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!
With regards to overriding domains in the hosts file, I have found that in some circumstances, Lion queries the IPv6 address for a domain if it senses that a domain is unreachable over the IPv4 network.
I discovered this when I noticed some ads that I had never seen before on Snow Leopard because I had redirected the ad domains to 127.0.0.1
. I fired up wireshark and noticed AAAA
(IPv6 DNS records) queries following the IPv4 A
queries (IPv4). The ad servers indeed have IPv6 addesses and were able to serve me their content.
The solution to this is have a
::1 mydomain.com
entry for every
127.0.0.1 mydomain.com
entry in your hosts file.
Interestingly, if you happen to have a local webserver running on 127.0.0.1:80
and your browser receives a response from the webserver (error or otherwise), no AAAA
query is issued, as it seems to be satisfied that a TCP connection was at least possible.
On a related note, if you make heavy use of the hosts file (for adblocking, local web development, etc), you may want to look into running your own local DNS resolver. There is a considerable disk/CPU hit from having to read /etc/hosts
on every request, so it is in your best interest to keep that file very light.
One advantage of running something like dnsmasq
locally (besides the significant performance boost) is that you can redirect whole top-level domains back to your local machine. This allows you to have the whole *.dev namespace for development (for instance), without having to individually enter every domain you want resolved locally into /etc/hosts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With