Understanding how DNS works needs a bit of an understanding the background process of a DNS Query.
The process of DNS Query involves,
1. An application that calls for a name resolution like Internet Explorer.
2. The DNS Client installed on the computer.
3. The local DNS server.
4. The various DNS servers on the Internet.
Lets discuss the process of a DNS Query with a simple example of accessing a website on the Internet.
1. When a user types in a website address in Internet Explorer say www.itsyourip.com and clicks GO, Internet Explorer does not directly understand the domain name and wouldn’t know where to go. Hence, picks up the website name www.itsyourip.com and pass it onto the DNS client to resolve the IP Address of the website.
2. The DNS Client also known as the DNS Resolver will try to resolve the IP address from its local resources which includes the Name to Address mappings in the HOSTS file and its local DNS cache. Normally, most of the DNS clients are capable of caching the previous DNS query results. The DNS resolver will use these available local resources and if it can’t find the IP Address will then query a DNS server that it knows to for the IP Address.
3. The DNS server will directly answer the query if it is the authoritative server for the particular domain (here www.itsyourip.com) else check its local cache of the previous queries. If it cannot find the IP Address then will query the DNS servers on the Internet.
The process it follows in contacting various DNS servers on the internet requires a bit of understanding of how it looks at the Domain name.
For instance the website address www.itsyourip.com will be looked at by the DNS server as .com.itsyourip.www
NOTE: Make a note of the "." before com.
The above indicates that
“.” is the ROOT DOMAIN.
“com” is Sub-domain for the ROOT Domain.
“itsyourip” is a sub-domain for “.com”
“www” is either a node (no further sub-domains) or further a sub-domain for "itsyourip".
4. Now, the DNS Server will query one of the root servers requesting for a list of Authoritative servers for the .COM domain. The Root server will respond with the list of servers addresses hosting the COM domain.
5. The DNS server will pick one from the list and contact that server for a list of Authoritative servers for the itsyourip domain. The server will respond with the details of the Authoritative server for the itsyourip domain.
6. Now, that the DNS server knows the Authoritative server address for the itsyourip.com domain and hence will directly contact the server for the IP Address of the host www which belongs to itsyourip.com (called as A Record). The Authoritative DNS server will then respond with the IP Address or a list of IP Address (if more than one server hosts the website www.itsyourip.com) for www. Itsyourip.com.
7. This the DNS server then returns back to the DNS client which again passes it onto the DNS application which initially requested the IP Address information, Internet Explorer in this case.
8. The Application then knows where to go to fetch the website. How it fetches the correct page etc is being taken care by the HTTP protocol using host headers etc.,
That is how a DNS Query works in its simplest terms. In any of the above when we query for a non-existent domain or a domain or the server that hosts the domain is not available will return an error.