DNS (Domain Name System)

Where are you going?

🌐 What is DNS?

  • 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?

  1. User-friendliness: Domain names are easier to remember than long numerical IP addresses.

  2. Scalability: DNS uses a distributed and hierarchical structure, enabling it to handle billions of domain names and IP addresses efficiently.

  3. Flexibility: DNS allows websites to change their IP addresses without affecting users. Updated DNS records ensure continued access via the same domain name.

  4. 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?

There are three main types:

  1. TLD (Top-Level Domains) – .com, .net, .org, .ninja, etc.

  2. ccTLD (Country Code TLDs) – .uk, .au, .fr, etc.

  3. sTLD (Sponsored TLDs) – .edu, .gov, .mil, used for specific institutions.

🧩 What are Subdomains?

Format: subdomain.domain.com

  • domain.com is your main (root) domain

  • subdomain 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 app

      • api.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 servers

  • Authoritative 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

  • 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:

  1. 🧠 Your device checks its local DNS cache (like a recent history).

  2. 🌐 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).

  3. πŸ“‘ If the DNS server doesn’t know either, it asks the root DNS servers where to look.

  4. πŸ” It follows a chain of servers until it reaches the name server for the domain.

  5. βœ… DNS resolver returns the correct IP address to your browser, which uses it to connect to the web server.

  6. πŸš€ The resolver caches the result for faster access next time and now your device can load the website!

Overview of How DNS works

πŸ“¦ Common DNS Record Types

Record
What it does
Example

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

🧠 Recap

  • 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