What is DNS and how does DNS lookup work?

DNS(Domain Name System) is a decentralized naming system that converts domain names(such as nlogn.in) to its corresponding IP addresses.

Each device connected to the internet has a unique IP address, which is a 32-bit number for example 152.52.0.1(in IPv4), and remembering such an IP address is almost impossible. The solution to this problem was using English letters, as we humans beings are good at memorizing English words. Hence the concept of Domain Name came into the picture. Each domain name is a combination of English alphabets(generally) and points to an IP address.

To create a mapping between domain names and IP addresses, DNS(Domain Name System) was introduced. Now, whenever a user types a domain name, the DNS translates it into corresponding IP addresses so browsers can load Internet resources.

Types of DNS Server

1. Root Domain Name Server

Root DNS servers are the first step in the process of resolution of Domain name into IP address. The mapping of a domain name to an IP address is a hierarchical process, and the distribution is done on the basis of DNS zones and Root DNS sits on the top of this hierarchy.

The root-level directly responds to the queries that are for the root zone or refer queries to appropriate TLD nameserver. Generally, most of the queries are contains referring to TLD’s hence Root DNS serves are not involved in name resolution.

There are a total of 13 root DNS around the globe starting with the letter a to m. Refer bottom for further insights.

2. Top-Level Domain (TLD) Server

Top-level domains are first-tier domains available for the use of the general public. They are installed in the Root DNS Server and all the other domains are the part of TLDs. For example, google.com or nlogn.in are top-level domains, while nlogn.co.in or google.co.in are secondary level domains.

Top-level domains are divided into two categories:

  1. Generic top-level domains (gTLD) — These are the domains that are not associated with any country. Example — .com, .org, .net, .int, .mil, .edu, .gov
  2. Country-code top-level domains(ccTLD) — These are 2 letter domains established for countries or territories. Example — .in, .uk, .to, .ca, .co, .us etc.

3. Authoritative DNS Server

It is the last stop for a DNS query and returns. It is a nameserver that has the original DNS records such as (A record, MX record, etc.). The request to them reach from resolving name servers and they are the endpoint of any request. Note, they don’t respond to recursive queries.


DNS Lookup

DNS lookup is a process by which an IP address(one of the DNS record) is returned for a domain name by a DNS server. The DNS is lookup is not only limited to returning the IP address, but it can also return all the records associated with a domain name(such as IP, IPv6 address or MX record, etc).

Image for post

Image for post

DNS Lookup

The request to DNS resolver is a recursive request while all other requests in the above diagram are simple(non-recursive) queries.

The above diagram explains how DNS lookup happens and how DNS routes traffic to a website.

  1. A user opens a web browser, enters nlogn.in in the address bar, and presses Enter button.
  2. The request for nlogn.in is routed to a DNS resolver, which is typically managed by the user’s Internet service provider.
  3. The DNS resolver forwards the request for nlogn.in to a root DNS server.
  4. The DNS resolver again forwards the request for nlogn.in, this time to one of the TLD name servers for .in domains. The name server for .in domains responds to the request with the names of the 2 or 4 (depending on the domain owner) name servers that are associated with the nlogn.in domain.
  5. The DNS resolver chooses a nlogn.in the authoritative name server and forward the request for nlogn.in to that name server.
  6. The website’s name server looks in the nlogn.in hosted zone for the nlogn.in A record, to get the associated value, such as the IP address for a web server, 34.72.102.28, and returns the IP address to the DNS resolver.
  7. The DNS resolver for the ISP finally has the IP address that the user needs. The resolver returns that value to the web browser. The DNS resolver also caches (stores) the IP address for nlogn.in for an amount of time that you specify so that it can respond more quickly the next time someone browses to nlogn.in
  8. The web browser sends a request for nlogn.in using the IP address that it got from the DNS resolver. This is where the actual content is. For example, a web server running on a Google VM instance that’s configured as a website endpoint.
  9. The web server or other resource at 34.72.102.28 returns the web page for nlogn.in to the web browser, and the web browser displays the page.

List of Important DNS record types

  1. A — Returns a 32-bit IP address, commonly used to map a domain name to IP addresses.
  2. AAAA — Returns a host 128-bit IPv6 address.
  3. CNAME — Alias one name to another. The DNS lookup will continue by retrying the lookup with the new name.
  4. TXT — It is used to hold some descriptive text.
  5. MX — Maps Mail Exchange servers to a domain name.
  6. NS — Name server record is used to identify the authoritative DNS server for a domain.

Further Note

  1. DNS server uses UDP(User Datagram Protocol) to serve requests.
  2. It works at port number 53.
  3. The DNS header size is 8 byte.
  4. DNS query consists of a single UDP request and a reply.
  5. DNS zone transfer is a process of replicating DNS databases across a set of DNS servers. DNS zone transfer uses TCP.
  6. To get the list of all the DNS records for a Domain name try $ dig any example.com
  7. There are a total of 13 logical Root DNS servers available around the world with from as letter.root-server.org and the letter ranges from a to m.

a.root-servers.org — 198.41.0.4

b.root-servers.org — 199.9.14.201

c.root-servers.org — 192.33.4.12

d.root-servers.org — 199.7.91.13

e.root-servers.org — 192.203.230.10

f.root-servers.org — 192.5.5.241

g.root-servers.org — 192.112.36.4

h.root-servers.org — 198.97.190.53

i.root-servers.org — 192.36.148.17

j.root-servers.org — 192.58.128.30

k.root-servers.org — 193.0.14.129

l.root-servers.org — 199.7.83.42

m.root-servers.org — 202.12.27.33

8. ICANN is assigned authority to monitor the operation of the root name server DNS.


Originally this post was published at nlogn.in

Phillip Ninan's photo

Nice article! Coming from AWS land using the term alias actually describes some additional functionality to DNS using Amazon Route 53. I thought that was a fun fact lol.

This Haiku always come to mind when discussing DNS. I felt it was appropriate.

image.png

Bolaji Ayodeji's photo

Such an amazing article, thanks for sharing!

Syed Fazle Rahman's photo

Great article, Mayank Joshi. Welcome to Hashnode. 🎉

Pranav Bhattarai's photo

nice. Write more like this. It would be very helpful.