Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OSX Lion DNS lookup order [closed]

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:

  1. Entries in /etc/hosts are resolved painfully slow
  2. You can't not override existing domains, e.g. 127.0.0.1 www.google.com
  3. If you get search domain entries from DHCP, let say .lan, and some funny guy configured localhost.lan to something else then 127.0.0.1 in the local DNS you can not reach your localhost anymore.

Is this behavior intended? Does it make any sense? And most important, how can I come back to the old behavior.

like image 951
Meik Avatar asked Jul 27 '11 08:07

Meik


People also ask

How do I do a DNS lookup?

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.

How do I use Ifconfig on Mac?

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.


2 Answers

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!

like image 186
Jean-Baptiste MONIN Avatar answered Oct 12 '22 05:10

Jean-Baptiste MONIN


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

like image 25
guns Avatar answered Oct 12 '22 05:10

guns