What Programmers Should Know About DNS

I’m not an expert about DNS, but I learned a few things over the years by talking to people like Spider, and have noticed that there are a lot of misconceptions among programmers. Here’s a quick brain dump:

  • DNS is distributed and fault-tolerant. It’s not very likely to fail.
  • In order to be faster, DNS queries are cached by your ISP and your computer. If you don’t want your DNS name to be cached because you want to point it to another IP very quickly, you can set the TTL to one second.
  • Most ISPs have crappy DNS servers.
  • DNS supports different record types. The record type you resolve when surfing the internet is an A record. Mail servers, on the other hand, ask for MX records. There are a lot of different record types.
  • DNS names can be specific, as in www.example.com, or wildcard, as in *.example.com. If no specific name is found for a DNS query, then you get the results for the longest matching wildcard.
  • A DNS query can return many IP addresses for a single name. This can be used for load-balancing, by having a web server return a bunch of IPs in random order for a single domain name, in which case your browser will try to connect to them one at a time until it succeeds.
  • A DNS query for SRV record can return a list of other DNS names and ports. This gives you a layer of indirection that can be used to hardcode a DNS name in your client program, which can then be used at run-time to figure out the real server and port to which it will connect. This is why you don’t have to enter the server address in Skype, Yahoo Messenger or Windows Messenger.

 
 
 

Leave a Reply