What is a DNS query?
A DNS query (also known as a DNS request) is a demand for information sent from a user's computer (DNS client) to a DNS server. In most cases a DNS request is sent, to ask for the IP address associated with a domain name. An attempt to reach a domain, is actually a DNS client querying the DNS servers to get the IP address, related to that domain.
Types of queries
In general, there are two ways of resolving a host or a domain name to an IP address, using the domain name system – a Recursive query and a non-Recursive query.
The Recursive query is, when a DNS client directly gets the IP address of a domain, by asking the name server system to perform the complete translation.
The non-Recursive query is, when a DNS client contacts the name servers, one by one, until it finds the server, containing the needed information.
How do they work?
The process behind Recursive queries, can be explained by the following example:
1. A user opens up his favorite browser and enters https://www.somedomain.com in the address bar. His computer does not know the IP address for www.somedomain.com, so it sends a request to the user’s DNS resolver.
2. The resolver does not know the IP address for www.somedomain.com, so it will query one of the root DNS servers.
3. The root servers know the locations of all the TLDs, such as .com, they do not know the IP of www.somedomain.com, so they return the location of the .com servers.
4. Once the query reaches the .com TLD servers, it will find the Authoritative DNS server of www.somedomain.com and will reply to the resolver with that server.
5. The resolver will send a query to the Authoritative DNS server of the domain and will resolve it.
6. The Authoritative DNS server of the domain will check within its database and will find an entry for www.somedomain.com, which has an IP address.
7. Finally the resolver will know the IP address for www.somedomain.com and will send the result to the user's computer.
The process behind non-Recursive queries, follows the same procedure, but the DNS client (the machine from which the user tries to resolve the domain) will have to find the authoritative DNS server for the domain, by itself.
The DNS client will have to ask by itself, first the root servers, then the TLD servers and finally the Authoritative DNS server to be able to resolve the domain.