Domain Name System (DNS)

I’ve had to see this term every time I deploy a website, but truth be told that I don’t know what this does. I finally get to understand how this works under the hood.

DNS translates Hostname to IP Addresses. That is all that it does!


The DNS is

  1. a distributed database implemented in a hierarchy of DNS servers, and
  2. an application-layer protocol that allows hosts to query the distributed database.

ahh, so like when you do

PING ( 56 data bytes is the Hostname, you do a lookup in the DNS, and get the IP address

Below are the exact steps:

  1. The browser extracts the hostname,, from the URL and passes the hostname to the client side of the DNS application.
  2. The DNS client sends a query containing the hostname to a DNS server.
  3. The DNS client eventually receives a reply, which includes the IP address for the hostname.
  4. Once the browser receives the IP address from DNS, it can initiate a TCP connection to the HTTP server process located at port 80 at that IP address.

And then you use something like nginx.

DNS is Decentralized

There are several advantages to a decentralized design:

  1. If a DNS server crashes, the entire internet doesn’t crash
  2. A single DNS server does not have to handle all DNS queries
  3. Multiple servers close to querying clients all across the globe
  4. Easier Maintenance

  • Root DNS Servers provide the IP addresses of the TLD servers.
  • Top-level domain (TLD) servers. For each of the top-level domains (.com, .net, etc.) there is TLD server (or server cluster). For example, Verisign maintains the .com domain
  • Authoritative DNS servers. (ex:,

If i am in Canada vs if I am in Europe and i enter, does that resolve to the same ip address?

No. This is thanks to a practice called Geolocation Routing.

DNS Records

Who pays for the DNS servers?

We just learned that DNS follows a hierarchy, so it depends:

  • For root servers, it’s like volunteers.
  • For TLD servers: this registrar (ex: GoDaddy) pays a fee to a domain name registry (ex:  Verisign which maintains .com domain) which maintains TLD servers.
  • For Authoritative servers: Domain registrars (ex: GoDaddy) maintain these. Remember that DNS is a mapping from a Hostname to an IP Address. You buy Hostname from domain providers like GoDaddy, and that is why you can configure the DNS there! It all makes sense now.

Medium article.

DNS Records and Messages

  • If Type=A, then Name is a hostname and Value is the IP address for the host- name. Thus, a Type A record provides the standard hostname-to-IP address map- ping. As an example, (,, A) is a Type A record.
  • If Type=NS, then Name is a domain (such as and Value is the host- name of an authoritative DNS server that knows how to obtain the IP addresses for hosts in the domain. This record is used to route DNS queries further along in the query chain. As an example, (,, NS) is a Type NS record.
  • If Type=CNAME, then Value is a canonical hostname for the alias hostname Name. This record can provide querying hosts the canonical name for a host- name. As an example, (,, CNAME) is a CNAME record.
  • If Type=MX, then Value is the canonical name of a mail server that has an alias hostname Name. As an example, (,, MX) is an MX record. MX records allow the hostnames of mail servers to have simple aliases. Note that by using the MX record, a company can have the same aliased name for its mail server and for one of its other servers (such as its Web server). To obtain the canonical name for the mail server, a DNS client would query for an MX record; to obtain the canonical name for the other server, the DNS client

would query for the CNAME record.