Skip to main content

Command Palette

Search for a command to run...

How Does the Internet Know Where a Website Lives?

Understanding DNS,dig, TCP, and More for Newbies

Published
16 min read
How Does the Internet Know Where a Website Lives?
D
I’m a Computer Science Engineer focused on backend development, scalable system design, and real-world production deployments. I build and deploy full-stack applications using Node.js, Express, MongoDB, Redis, Docker, and CI/CD pipelines.

The First Question Everyone Should Ask

“How does a browser know where a website lives?”

When you type a web address into your browser, have you ever thought about how it finds the website on the internet? This process involves several steps that work together to show you the web page you want.

First, the browser looks in its cache to see if it has recently visited the website and saved its location. If not, the browser asks a Domain Name System (DNS) server for help. The DNS server works like a phone book for the internet, changing the web address you typed into an IP address, which is the website's actual location online.

With the IP address, the browser can connect to the server where the website is stored. It sends a request over the internet to the server, which then sends the website's data back to the browser. The browser processes this data and displays the web page for you to see and use.

This whole process happens in just a few seconds, letting you access websites quickly. Knowing how this works can help you appreciate the technology behind the internet and the complexity of simply visiting a website.

www.google.com

DNS = The Phonebook of the Internet

What is DNS?

DNS, or Domain Name System, is like the phonebook of the internet. It helps connect users to websites by changing easy-to-remember domain names into IP addresses that computers use.

  • People find it easy to remember names like google.com.

  • Computers understand numbers like 142.250.195.14.

The main job of DNS is:

To change names into numbers

Here's how it works:

  • Think of a name: Ramesh

  • And a matching phone number: 98765xxxxx

Similarly, DNS takes a website name that people can easily remember and turns it into an IP address that computers understand. This process lets your browser find and open the website you want, making browsing easy. Without DNS, using the internet would be harder because users would have to remember number-based IP addresses.for every website.


WWhy is DNS needed?

If there were no DNS:

  • You would have to remember the IP address for every website.

  • If an IP changed, the website would become inaccessible.

  • The internet would be unusable for humans.

DNS makes the internet human-friendly.


When is DNS used?

With every single website request.
Every time you type a website address into your browser or click a link, DNS is at work behind the scenes. Whether you realize it or not, DNS is always the first step in the process of connecting you to the internet. When you enter a domain name, DNS translates it into the corresponding IP address, allowing your browser to locate and access the website's server. This happens seamlessly and almost instantly, ensuring that you can navigate the web without needing to understand the complex numerical addresses that computers use to communicate. Without DNS, accessing websites would be cumbersome and impractical for users, as they would need to memorize and input long strings of numbers for every site they wish to visit.


What Are DNS Records and Why Are They Important?

Imagine a domain as a house.
DNS records are like the official information slips for that house. These records contain crucial details about the domain, similar to how a house's address and ownership details are recorded in official documents. DNS records specify various types of information, such as the IP address associated with the domain, mail server details for handling emails, and other essential data that helps direct internet traffic correctly. They ensure that when someone tries to visit a website or send an email, their request is routed to the correct server, much like how a postal service uses an address to deliver mail to the right location. Without these records, navigating the internet would be chaotic, as there would be no organized way to connect domain names with their corresponding servers.


NS Record — "Who is the boss of this domain?"

What is an NS Record?

An NS (Name Server) record is a crucial part of the DNS system that specifies which name servers are authoritative for a particular domain. Essentially, it indicates:

Who is responsible for managing the DNS records of this domain

These records are vital because they direct internet traffic to the correct servers, ensuring that when someone types a domain name into their browser, they are connected to the right website. The NS record acts like a guide, pointing to the servers that hold the authoritative DNS records for the domain. This setup allows for efficient and accurate routing of requests, making sure that users can access websites quickly and reliably. Without NS records, the internet would struggle to function smoothly, as there would be no clear direction on where to find the necessary DNS information for each domain.

Example:

example.com → ns1.cloudflare.com

Why Does an NS Record Exist?

The internet needs to know:

  • Who to ask for information?

  • Which server has the final answer?

An NS record is important because it assigns responsibility for managing a domain's DNS records. It tells the internet which name servers are in charge of a domain, directing requests to the right servers. This makes sure that when someone types a domain name into their browser, the internet knows exactly where to send the request to get the correct website. Without NS records, there would be confusion about which servers have the needed information, causing possible delays or failures in connecting users to websites. So, NS records are crucial for keeping the internet running smoothly and efficiently.


WHEN used?

  • During domain lookup

  • In the Root → TLD → Authoritative flow


A Record — “Where is the home of this domain?”

WHAT is an A Record?

An A record, or Address record, is a crucial component in the Domain Name System (DNS) that links a domain name to its corresponding IPv4 address. This record essentially acts as a map, guiding internet traffic to the correct server where the website is hosted. When you type a domain name into your browser, the A record is what helps translate that human-readable name into a numerical IP address that computers use to locate and connect to each other over the internet.

Domain → IPv4 address

For instance, when you enter a domain like example.com, the A record will direct your request to the specific IPv4 address where the website's server is located. This process is similar to looking up a street address in a phone book to find a friend's house. Without A records, users would have to remember complex numerical IP addresses instead of simple domain names, making the internet much less user-friendly. A records are essential for ensuring that users can easily and reliably reach the websites they want to visit.

google.com → 142.250.195.14

Why is an A Record needed?

  • Browsers require an IP address to connect.

  • A domain is simply a user-friendly name.


When is it used?

  • When opening a website

  • Before making a TCP connection to the server


AAAA Record — The IPv6 Version of an A Record

What is an AAAA Record?

An AAAA record serves a similar purpose to an A record, but it is specifically designed for the newer IPv6 protocol. Just like an A record maps a domain name to an IPv4 address, an AAAA record links a domain name to an IPv6 address. This is crucial as the internet transitions to IPv6 due to the exhaustion of available IPv4 addresses.

Domain → IPv6 address

The AAAA record ensures that when you type a domain name into your browser, it can be translated into an IPv6 address, allowing your device to connect to the server hosting the website. This process is essential for maintaining seamless internet connectivity as more devices and services adopt IPv6. Without AAAA records, users would face difficulties accessing websites that operate on IPv6, as they would need to remember lengthy and complex IPv6 addresses. Therefore, AAAA records play a vital role in supporting the growth and scalability of the internet by facilitating the use of IPv6.

Example:

google.com → 2404:6800:4009:80b::200e

Why does it exist?

  • IPv4 addresses are running out

  • IPv6 is a future-proof solution


CNAME Record — “This name is an alias for that name”

What is a CNAME Record?

A CNAME record, short for Canonical Name record, is a DNS record that links one domain name to another. It's useful when you want a subdomain to point to an external domain or when multiple domain names should lead to the same place. With a CNAME record, you can manage domain names more easily, and any changes to the main domain automatically update the alias domain.

For example, if your main website is example.com and you want blog.example.com to point to a different server, you can use a CNAME record. This record will direct blog.example.com to the server hosting the blog, even if it's under a different domain.

This setup helps manage multiple services under one main domain without updating each DNS record separately. It also makes redirecting traffic and managing domain aliases easier, ensuring users can access the content they want without issues.

Example:

  • blog.example.comhostingprovider.com

  • shop.example.comstorefront.com

Using CNAME records keeps your DNS organized, making domain management simpler and ensuring your online presence is consistent and easy to access.

www.example.com → example.com

Why is a CNAME needed?

  • Access one server using multiple names

  • Manage IP changes from one place


CCOMMON CONFUSION (Important!)

A vs CNAME

  • A → points to an IP address

  • CNAME → points to another domain name

CNAME never points to an IP address


MX Record — "Where Will Emails Be Delivered?"

What is an MX Record?

An MX (Mail Exchange) record is a DNS record that tells which mail server should get emails for a domain. It guides the internet on where to send emails for addresses at that domain.

For example, if you own "example.com," the MX record directs emails sent to "info@example.com" or "support@example.com" to the right mail server. This ensures emails reach the correct server for the intended recipients.

How Does an MX Record Work?

When someone emails an address at your domain, the sending mail server checks the DNS for your domain's MX record. This record has the mail server's name that should get the email. The sending server then connects to this mail server to deliver the email.

Why Are MX Records Important?

MX records are key for making sure emails go to the right place. They let domain owners set up multiple mail servers for backup, so if one server fails, another can handle the emails. This setup improves the reliability and availability of email services.

example.com → mail.google.com

Why MX Record?

  • Email traffic is different from web traffic.

  • Emails require a separate server..


COMMON CONFUSION

NS vs MX

  • NS → DNS responsibility

  • MX → Email delivery


TXT Record — “Extra Notes and Verification”

What is a TXT Record?

A TXT record is a type of DNS record that lets domain administrators store text information in the domain's DNS settings. Here are the main uses of a TXT record:

  • Extra Information: TXT records can hold extra data about a domain that might be useful for different purposes. This data can include descriptive text about the domain or instructions for how certain services should interact with it.

  • Ownership Verification: One main use of TXT records is to verify domain ownership. When setting up services like Google Workspace or Microsoft 365, you might be asked to add a specific TXT record to your domain's DNS. This record shows that you have control over the domain.

  • Security Checks: TXT records are important for improving email security through tools like SPF (Sender Policy Framework) and DKIM (DomainKeys Identified Mail). SPF records state which mail servers can send emails for your domain, helping to stop spoofing. DKIM adds a digital signature to emails, letting recipients verify that the email was really sent from your domain and hasn't been changed. These security measures help protect against phishing and spam.

By using TXT records, domain owners can ensure better management, security, and verification of their domain.mains.


WHY TXT exists?

  • To prove to Google that the domain is yours

  • To prevent email spoofing

  • To store custom metadata


How All DNS Records Work Together (One Website)

For example.com:

  • NS → kaun manage karega

  • A / AAAA → website kaha host hai

  • CNAME → aliases

  • MX → email routing

  • TXT → verification + security

Sab milkar ek complete digital identity banate hain


dig Command — The X-ray Machine of DNS

WHAT is dig?

dig is a tool that:

Shows what's happening inside DNS

The dig command, short for Domain Information Groper, is a strong and flexible tool used to check DNS records. It helps users look into and fix DNS problems by giving detailed information about DNS servers and their records. With dig, you can see how DNS queries are answered and understand how information moves from one server to another. This tool is crucial for network administrators and developers who need to make sure domain settings are correct and DNS records work as they should. Whether you're checking DNS changes or solving connection issues, dig gives a clear and complete view of the DNS system.ape.


WHY dig?

  • Debug DNS issues

  • Understand the flow of DNS resolution

  • Gain insights into system design


DNS Resolution Layers (Mental Model)

Root → TLD → Authoritative

dig . NS

  • Root name servers

  • Starting point of the Internet


dig com NS

  • Responsible servers for .com

dig google.com NS

  • Google's authoritative DNS servers

dig google.com

  • Final IP address is found

  • This output is what the browser uses


TCP & UDP — Rules for Sending Data

WHAT is TCP?

TCP, short for Transmission Control Protocol, is a key Internet protocol. It makes sure data is sent safely, reliably, and in the right order across networks. When data is sent with TCP, it's split into smaller packets. These packets are sent to the destination, where TCP puts them back together in the right order. This ensures the data arrives complete and in the right sequence, like a courier service that delivers your package safely and in the correct order. TCP is commonly used for tasks where data accuracy and order matter, like web browsing, email, and file transfers.s.


WHAT is UDP?

UDP, or User Datagram Protocol, is another key Internet protocol. Unlike TCP, UDP focuses on speed and efficiency, sending data quickly rather than ensuring reliability. Data sent with UDP is broken into small units called datagrams and sent without first making a connection. This means there's no guarantee the data will arrive complete or in the right order, similar to a loudspeaker announcement where the message is broadcast quickly, but there's no way to make sure everyone hears it correctly or in the right order.

UDP is useful when speed is more important than accuracy. It's often used for live video or audio streaming, online gaming, and other real-time services where delays are not acceptable, and some data loss is okay. In these cases, the goal is to deliver data as fast as possible, even if some packets are lost along the way.y.


When to Use TCP?

  • Websites

  • Emails

  • File transfers


When to Use UDP?

  • Video streaming

  • Online gaming

  • Live calls


HTTP — The Language of Websites

What is HTTP?

  • HTTP is the rule for communication between a browser and a server.r.

IIMPORTANT CLARIFICATION

It's important to know the difference between HTTP and TCP because they have different roles in internet protocols.

❌ HTTP ≠ TCP
✅ HTTP works on top of TCP

TCP (Transmission Control Protocol):

  • TCP makes sure data is sent accurately and in the right order. It creates a connection between the sender and receiver for reliable communication. This means data sent with TCP will reach its destination without errors and in the correct sequence. This reliability makes TCP perfect for tasks where accuracy is essential, like web browsing, email, and file transfers.

HTTP (Hypertext Transfer Protocol):

  • HTTP is used to transfer web pages over the internet. It sets the rules for how messages are formatted and sent, and how web servers and browsers should react to commands. HTTP uses TCP's reliable delivery to make sure web pages are correctly delivered to users. In short, TCP handles data delivery, while HTTP focuses on the structure and content of the messages being exchanged.changed.

TCP Deep Dive (Beginner Friendly)

Why is TCP needed?

Without rules:

  • Data gets lost

  • Order gets messed up

  • Duplicate packets


TCP 3-Way Handshake

The TCP 3-way handshake is a process used to establish a reliable connection between a client and a server. This handshake ensures that both parties are ready to communicate and that the connection is set up correctly before any actual data is exchanged. It involves three key steps: SYN, SYN-ACK, and ACK.

Step 1: SYN

In the first step, known as SYN (short for synchronize), the client initiates the connection by sending a SYN packet to the server. This packet is like a friendly greeting, indicating that the client wants to start a conversation. It includes an initial sequence number, which is used to keep track of the data packets being sent. Essentially, the client is saying, "Hello, can we start a conversation?" This step is crucial for establishing the initial parameters of the connection, such as sequence numbers and window sizes, which are important for managing data flow and ensuring that packets are delivered in the correct order.


Step 2: SYN-ACK

In the second step of the TCP 3-way handshake, known as SYN-ACK, the server responds to the client's initial SYN packet. This response is a combination of two actions: acknowledging the receipt of the SYN packet and sending its own SYN packet back to the client. The server's SYN-ACK packet serves as a confirmation that it has received the client's request to establish a connection and is ready to proceed with the communication. It includes an acknowledgment number, which is the client's initial sequence number incremented by one, confirming the receipt of the SYN packet. Additionally, the server sends its own initial sequence number, indicating that it is prepared to start sending data. This step is akin to the server saying, "Yes, I am ready to communicate, and here is my sequence number for our conversation." This exchange ensures that both the client and server are synchronized and ready to manage the flow of data efficiently.


Step 3: ACK

In the third and final step of the TCP 3-way handshake, known as ACK, the client sends an acknowledgment packet back to the server. This packet confirms that the client has received the server's SYN-ACK packet and is ready to establish a reliable connection. The acknowledgment packet includes a sequence number that is one more than the server's initial sequence number, indicating that the client is prepared to receive data from the server. By sending this ACK packet, the client effectively says, "I have received your sequence number, and I am ready to start our communication." Once this packet is received by the server, the connection is officially established, and both parties can begin exchanging data. This step completes the handshake process, ensuring that both the client and server are synchronized and ready to communicate efficiently. The successful completion of this step is crucial for the reliable transmission of data over the network. Connection established.


Data Transfer in TCP

  • Sequence numbers

  • Acknowledgements

  • Retransmission if lost


Connection Close

  • FIN → "I am finishing"

  • ACK → "Message received"


Final Mental Picture

Browser
  ↓
DNS (find IP)
  ↓
TCP (safe connection)
  ↓
HTTP (request/response)
  ↓
Server

Understanding Website Locating on the Internet