How DNS Works
When you type a URL into your browser, the browser's first step is to convert the domain name and host name into an IP address so that the browser can go request a Web page from the machine at that IP address. To do this conversion, the browser has a conversation with a name server.
The browser therefore contacts its name server and says, "I need for you to convert a domain name to an IP address for me." For example, if you type "www.101easyhosting.com" into your browser, the browser needs to convert that URL into an IP address. The browser will hand "www.101easyhosting.com" to its default name server and ask it to convert it.
The Distributed System
Name servers do two things all day long:
- Accept requests from programs to convert domain names into IP addresses.
- Accept requests from other name servers to convert domain names into IP addresses.
When a request comes in, the name server can do one of four things with it:
- It can answer the request with an IP address because it already knows the IP address for the domain.
- Contact another name server and try to find the IP address for the name requested. It may have to do this multiple times.
- "I don't know the IP address for the domain you requested, but here's the IP address for a name server that knows more than I do."
- Return an error message because the requested domain name is invalid or does not exist.
- Let's assume, however, that the name server has to start from scratch because it doesn't know the IP address.
A name server would start its search for an IP address by contacting one of the root name servers. The root servers know the IP address for all of the name servers that handle the top-level domains. Your name server would ask the root for www.101easyhosting.com, and the root would say (assuming no caching), "I don't know the IP address for www.101easyhosting.com, but here's the IP address for the COM name server." Every name server has a list of all of the known root servers. It contacts the first root server in the list, and if that doesn't work it contacts the next one in the list, and so on.
The root server knows the IP addresses of the name servers handling the several hundred top-level domains. It returns to your name server the IP address for a name server for the COM domain. Your name server then sends a query to the COM name server asking it if it knows the IP address for www.101easyhosting.com. The name server for the COM domain knows the IP addresses for the name servers handling the 101easyhosting.com domain, so it returns those. Your name server then contacts the name server for 101easyhosting.com and asks if it knows the IP address for www.howstuffworks.com. It does, so it returns the IP address to your name server, which returns it to the browser, which can then contact the server for www.howstuffworks.com to get a Web page.
One of the keys to making this work is redundancy. There are multiple name servers at every level, so if one fails, there are others to handle the requests. There are, for example, three different machines running name servers for101easyhosting.com requests. All three would have to fail for there to be a problem.
The other key is caching. Once a name server resolves a request, it caches all of the IP addresses it receives. Once it has made a request to a root server for any COM domain, it knows the IP address for a name server handling the COM domain, so it doesn't have to bug the root servers again for that information. Name servers can do this for every request, and this caching helps to keep things from bogging down.
Name servers do not cache forever, though. The caching has a component, called the Time To Live (TTL), that controls how long a server will cache a piece of information. When the server receives an IP address, it receives the TTL with it. The name server will cache the IP address for that period of time (ranging from minutes to days) and then discard it. The TTL allows changes in name servers to propagate. Not all name servers respect the TTL they receive, however. When HowStuffWorks moved its machines over to new servers, it took three weeks for the transition to propagate throughout the Web. We put a little tag that said "new server" in the upper left corner of the home page so people could tell whether they were seeing the new or the old server during the transition.