Table of contents
Domain Name System (DNS) server is a hierarchical system which translates domain names into IP addresses and enables devices to locate each other over the TCP/IP network. Without DNS you would have to remember 157.240.22.35 every time you want to see what’s going on with your friend who’s on Facebook. Or 23.67.33.29 whenever you crave a McD burger. That’s tedious work for your mind that you, of course, don’t want. You can also argue that, even by using these IP addresses, you are not landing on the website’s page. I know this can happen because of several reasons, like
Host Header Requirements
SSL/TLS Certificates
Multiple Websites on One IP
Firewall and Security Restrictions
CDN and Load Balancing
but don’t trouble yourself with these. Eventually you will understand these with time. The concept is that DNS servers can map human-readable websites to their IP addresses, but we humans can’t remember all the IPs of our favorite websites, and even if we do, we can’t access them like that, because these days websites are designed to be accessed using their domain names for all the reasons I mentioned earlier (security, load balancing).
DNS Caching
DNS caching is when your browser, OS, and ISP store the IP addresses of recently visited websites locally, for a specific amount of time known as the Time-to-Live (TTL), so that it doesn't have to ask a DNS server every time the same site is visited and thus, speeds up the whole process.
Host File
A host file is a local text file used to map domain names to IP addresses without querying a DNS server. You can manually enter domain names and their IPs into your host file to override DNS if you want. This is how a typical host file looks like:
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each entry
should be kept
# on an individual line. The IP address should be placed in the first column
followed by
# the corresponding host name. The IP address and the host name should be
separated by at
# least one space.
#
# Additionally, comments (such as these) may be inserted on individual lines or
following
# the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.0 google.com
All the lines starting with ‘#‘ are comments. Just like 127.0.0.0 google.com (this is just an example), you can add your own mappings, but be aware - If wrong websites suddenly start showing up 😭, check your hosts file to see whether it’s been tampered.
Stub resolver
A stub resolver is a DNS client built into your operating system that handles initial DNS queries by checking local resources (cache/hosts file) before forwarding requests to a full DNS resolver if needed. It is called a ‘stub‘ because it "stubs" off the actual querying work to another server and handles only the initial step of sending the query and receiving the final result.
See the flow:
Before querying DNS servers, stub resolver first checks the -
DNS Cache (also called DNS resolver cache), and if not found
Checks the host file
If still not found, the stub resolver then forwards the query to some DNS server
For example, when you type "google.com" in your browser, the browser asks the stub resolver for the IP address, and the stub resolver checks with the DNS cache; if not found, then with the host file, and if still not found, then queries the DNS server.
URL Structure
Scheme: Tells what protocol to use (like http:)
Authority: The hostname (like google.com) plus optional username and port number.
Path: The specific resource location on server, starting with slash (like /travel/mountain.jpg).
Query: Extra information sent to server after ?, using key=value pairs (like ?name=keshav&age=5).
Fragment: Points to specific section within a resource, marked with # (like #hero-section).
Let’s see the different parts of this URLhttp://shree_krishna@mywebsite.com:8080/docs/happy.html?lang=en&theme=dark#section3
Scheme:
http://
Authority:
shree_krishna@mywebsite.com:8080
Username:
shree_krishna
Host:
mywebsite.com
Port:
8080
Path:
/docs/happy.html
- Filename:
happy.html
- Filename:
Query:
?lang=en&theme=dark
- Key-value pairs:
lang=en
,theme=dark
- Key-value pairs:
Fragment:
#section3
Fully Qualified Domain Name (FQDN)
Domain names ending with trailing dot are called fully qualified domain. FQDNs are also called absolute domains. Therefore simply, domains which don’t end with a trailing dot are called relative domains.sales
and development.test
are relative domains, whereas sales.nike.com.
or development.test.happy.com.
are FQDN. Look for the trailing dot in the latter two 👀
Bear with me, here’s a simple analogy
Relative: Krishna from Mathura
Absolute: Shree Krishna from Mathura, Uttar Pradesh, India
Relative and FQDNs are often used interchangeably since software resolves the relative name by adding necessary parts to make it a fully qualified domain name (FQDN) that ends with a dot (.
), indicating the root (top most level) of the DNS hierarchy.
Root Name Servers
The DNS root servers are essential to the internet, they directs queries to the DNS servers for each top-level domain (TLD). These servers then point to the DNS servers for subdomains. Root servers handle a lot of traffic daily and they are key in keeping the internet functional. There are 13 root servers globally, and DNS servers locate them using a root hints file.
Here’s the list of all the 13 servers
Server | IP Address | Operator |
A | 198.41.0.4 | VeriSign Global Registry Services |
B | 170.247.170.2 | University of Southern California |
C | 192.33.4.12 | Cogent Communications |
D | 199.7.91.13 | University of Maryland |
E | 192.203.230.10 | NASA Ames Research Center |
F | 192.5.5.241 | Internet Systems Consortium |
G | 192.112.36.4 | U.S. Department of Defense (NIC) |
H | 198.97.190.53 | U.S. Army Research Lab |
I | 192.36.148.17 | Netnod |
J | 192.58.128.30 | Verisign, Inc. |
K | 193.0.14.129 | RIPE NCC |
L | 199.7.83.42 | ICANN |
M | 202.12.27.33 | WIDE Project |
Top Level Domain (TLD)
A top-level domain appears just below/after the root domain. Top-level domains have two categories: generic domains and geographic/country code domains.
Generic Domain: TLDs that represent general categories, such as
.com
for commercial use or.org
for organizations. More such are.edu
,.gov
,.int
,.mil
,.net
,.name
,.museum
,.info
,.coop
,.aero
,.biz
,.pro
,.ai
,.tech
,.camp
,.bike
,.life
,.tech
,.food
,.chat
,.film
,.guru
,.mom
, etc.Geographic Domain: These are TLDs linked to specific locations, like
.in
for the India or.fr
for France. More such are.ca
,.gr
,.hr
,.de
, etc.
What are DNS Server?
A DNS server is a computer running DNS software that manages the DNS database and handles name resolution requests from other devices. But there’s a catch!? One server does not hold the entire database of domains, subdomains, and hosts. The DNS database, which maps domains, subdomains, and hosts, is distributed across multiple servers worldwide. No single server holds the entire database. Different parts are managed by specific servers across the internet. Read along to find out the secret sauce.
Zones
See, to simplify DNS management, the DNS namespace (I have got your back, think of namespace as a system) is divided into zones, each managed by a specific server. Typically, zones align with domains—for instance, a domain like “krishna.com” can have a DNS zone managing it entirely. Subdomains can be split into separate zones. For example, “krishna.com” could have one zone for “happy.krishna.com” and another for the rest of “krishna.com”. This division allows authority for each zone to be delegated to different servers for better management.
Primary and Secondary servers
A primary server hosts a zone's data, storing it in files and acting as the main source. Every zone must have one primary server. A secondary server copies data from the primary server, ensuring a backup. With at least one secondary server, the domain remains accessible even if the primary server goes down.
Recursive Query VS Iterative Query
Listen up!
Recursive query - In this the DNS server retrieves the IP or returns an error if the hostname doesn't exist, asking other servers if needed.
Iterative query - In this the server provides the IP(if known) or a referral to another server that may have the answer.
This might me overwhelming. Hold on. Here is a simple Analogy.
Recursive Query: You ask a friend for directions, and they either give you the exact address or go ask others until they find the answer, then come back and tell you.
Iterative Query: You ask a friend for directions, and if they don’t know, they point you to someone else who might. You then go and ask that person yourself.
Zone File
Every DNS zone has all its information in a file called the zone file. And these files consist of some entries, called resource records. Each zone file can have multiple resource records.
This is the format of a zone file: Owner, TTL (time to live), Class, Type, RDATA
Resource Records
Specific Information about zones are written in Resource records. Each resource record, contains different kind of information.
SOA (start of authority) - Defines the start of a DNS zone, indicating the primary DNS server and zone settings.
NS (name server) - Specifies the authoritative DNS servers for a domain.
A (address) - Maps a domain name to an IP address.
CNAME (canonical name) - Redirects a domain name to another domain name (alias). If you read about this more, you will understand how redirection works.
MX (main exchange) - Specifies mail servers for a domain to handle email.
PTR (pointer) - Maps an IP address to a domain name for reverse DNS lookups.
Authoritative Name Servers (ANS)
These are the servers that store and serve DNS records (like A, NS, CNAME, and MX) for your domain. They are authoritative for the domain because they contain the definitive information. There’s a common misconception around that ANS are directly tied to domain registrars (like GoDaddy, Namecheap, etc.), but they have different roles. If you configure DNS records at GoDaddy's DNS management system, then GoDaddy’s DNS servers (like ns1.godaddy.com) become the ANS for your domain. But there’s no hard and fast rule that you have to use their service. So, you can, of course, use an external DNS service, such as Cloudflare or AWS Route 53, then their servers become the ANS for your domain.
Enough of learning new stuffs, now let’s connect the dots…
See the flow:
Let’s say when you type choosemybicycle.com (I love bicycles, wink wink) in your browser, your computer (stub resolver) first checks its local cache and host file for the IP address. If it's not found, it sends a query to your DNS resolver (recursive query). The resolver starts the process by asking the root DNS servers, which then direct it to the .com TLD servers (choosemybicycle.com). These TLD servers point to the authoritative name servers for choosemybicycle.com. (maybe ns.godaddy.com or ns.cloudflare.com or maybe something else 😅) The primary server holds the domain’s zone file, which includes records like the A record that maps the domain to its IP address. The resolver retrieves the IP and sends it back to your computer’s stub resolver, which allows your browser to connect to the website.
Yeah, that was it, a small read about DNS (not so small and probably boring; ahh, I suck at writing). Now you can go ahead and read about everything mentioned here in more detail. I promise it's much more interesting than you felt till now (oh boy, see how much I suck at writing).