DNS (Domain Name System)
Where are you going?
What is DNS?
DNS stands for Domain Name System, is a crucial component of the internet that translates human-readable domain names (e.g., thomasbui.gitbook.io) into IP addresses (e.g., 198.50.25.2) that computers use to identify each other. Essentially, DNS acts like a phonebook for the internet, allowing users to access websites using familiar domain names rather than complex IP addresses.
You type a domain name like
thomasbui.gitbook.io
into your browser.DNS translates that into an IP address like
104.21.38.139
, which your computer needs to actually find and talk to the website.
So instead of memorizing numbers, we just remember names β way easier for humans!
Why Do We Need DNS?
User-friendliness: Domain names are easier to remember than long numerical IP addresses.
Scalability: DNS uses a distributed and hierarchical structure, enabling it to handle billions of domain names and IP addresses efficiently.
Flexibility: DNS allows websites to change their IP addresses without affecting users. Updated DNS records ensure continued access via the same domain name.
Load balancing: DNS can distribute incoming traffic across multiple servers, enhancing website performance and reliability.
DNS Components and Terminology
There are 3 main components of DNS
Domain names, TLDs, and Subdomains
DNS Servers
DNS Resolvers
What is a Domain Name?
Itβs the friendly name for a website. You can register your own (like thomasbui.dev
) through a domain registrar.
There are three main types:
TLD (Top-Level Domains) β
.com
,.net
,.org
,.ninja
, etc.ccTLD (Country Code TLDs) β
.uk
,.au
,.fr
, etc.sTLD (Sponsored TLDs) β
.edu
,.gov
,.mil
, used for specific institutions.
What are Subdomains?
A subdomain is a prefix added before the main domain, separated by a dot. It's used to organizeA subdomain is a prefix added before the main domain, separated by a dot. Itβs used to organize and navigate to different sections of a website or web service.
Format: subdomain.domain.com
domain.com
is your main (root) domainsubdomain
is a separate branch or namespace under the main domain
For example:
shop.amazon.com
blog.google.com
api.github.com
Why Do We Need Subdomains?
They are used to:
Separate concerns/services: You can isolate different parts of your application or services
Organize content or regions:
Specify regional or language-specific content such as:
us.example.com
,vn.example.com
Specify user-specific subdomains in muti-tenant apps such as:
company1.saasapp.com
,company2.saasapp.com
Improve security:
You can sandbox subdomains to limit the blast radius if a vulnerability is found (e.g, separate cookies or CORS policies)
Example:
auth.example.com
handles authentication with tighter security settings
Independent development or deployment:
Different subdomains can be built and deployed independently
user.example.com
may run a React appapi.example.com
might run a Node.js backend
SEO & Branding: Subdomains can be used for specific marketing compaigns or microsites (e.g.,
promo.example.com
)
DNS Servers
There are 3 main components in DNS Servers
Root Servers: These servers are in the top of DNS hierarchy, directing queries to TLD servers. There are 13 root server clusters globally
TLD Servers: These servers will store details about domains within their TLD (like
.com
). They guide queries to the appropriate authoritative name serversAuthoritative Name Servers: They contain DNS records (e.g., A, AAAA, CNAME) for a domain and provide the final IP address to resolve a domain name
DNS Resolvers
A DNS resolver (also called a recursive resolver) is a server that takes a human-friendly domain name (like thomasbui.gitbook.io
) and finds the corresponding IP address (like 93.184.216.34
) so your browser can load the website.
Stub Resolver: Runs on user devices, sending DNS queries to configured DNS servers (like Googleβs 8.8.8.8).
Recursive Resolver: A DNS server that queries other DNS servers (root, TLD, authoritative) on behalf of the client until an IP address is found.
Caching-Only Resolver: Stores DNS records temporarily (based on TTL) to reduce future lookup times.
Forwarder: Forwards DNS queries to another server, often used in corporate settings for centralized DNS management.
Iterative (Non-Recursive) Resolver: Responds with cached answers or referrals but does not follow the entire DNS resolution chain.
How DNS Works Under The Hood?
When you visit a website:
Your device checks its local DNS cache (like a recent history).
If itβs not found, your device asks your DNS server (usually your ISP or a public DNS provider like Google -
8.8.8.8
or Cloudflare -1.1.1.1
).If the DNS server doesnβt know either, it asks the root DNS servers where to look.
It follows a chain of servers until it reaches the name server for the domain.
DNS resolver returns the correct IP address to your browser, which uses it to connect to the web server.
The resolver caches the result for faster access next time, and now your device can load the website!

Common DNS Record Types
A
Maps domain to IPv4 address
example.com β 1.2.3.4
AAAA
Maps domain to IPv6 address
example.com β 2001:db8::1
MX
Mail server for the domain
example.com β mail.example.com
CNAME
Alias of another domain
shop.example.com β shops.myshopify.com
NS
Specifies name servers for a domain
Tells where DNS records are managed
TXT
Text info β used for verification, anti-spam, etc.
Proves you own the domain, etc.
PTR
Reverse lookup (IP β domain name)
8.8.8.8 β dns.google
TL;DR
DNS turns domain names into IP addresses so computers can find each other.
Subdomains are customizable parts of your domain (
api.github.com
).DNS works by checking local, ISP, and internet-level servers until it finds the right one.
There are different record types that control how your domain behaves β from website direction to email handling and ownership proof.
Last updated