What Is DNS ( Domain Name System)

💡 What Is DNS 💡
DNS stands for Domain Name System. It is essentially the “phonebook of the Internet.”
Here’s what it does:
Purpose:
Computers communicate using IP addresses (like192.168.1.1
or2606:4700:4700::1111
), but humans find it easier to remember domain names (likegoogle.com
). DNS translates these human-friendly domain names into machine-friendly IP addresses.How it Works (Basic Flow):
You type a URL (e.g.,
www.example.com
) in your browser.Your computer asks a DNS resolver (usually provided by your ISP) for the IP address of
www.example.com
.The resolver checks its cache. If it doesn’t have it, it queries DNS servers in a hierarchical order:
Root DNS servers – point to the Top-Level Domain (TLD) servers (like
.com
,.org
).TLD DNS servers – point to the authoritative DNS server for that domain.
Authoritative DNS server – provides the IP address of the requested domain.
The resolver returns the IP address to your computer, which then connects to the website.
Components of DNS:
DNS Resolver: The client-side service that queries DNS servers.
Root Servers: Top of the DNS hierarchy, direct queries to TLD servers.
TLD Servers: Handle top-level domains like
.com
,.net
,.org
.Authoritative DNS Servers: Store actual IP addresses for domains.
DNS Records: Information stored in DNS, e.g.:
A record – maps domain to IPv4 address.
AAAA record – maps domain to IPv6 address.
CNAME record – alias to another domain.
MX record – mail server for the domain.
Why DNS is Important:
Makes the Internet user-friendly.
Supports website availability and email routing.
Essential for almost all network communications.
Extra Info:
DNS uses port 53 and typically uses UDP (sometimes TCP).
DNS caching improves performance and reduces repeated lookups.
In short: DNS converts human-readable names into machine-readable IP addresses so that computers can find each other on the Internet.
DNS Servers are specialized computers or services that store, manage and respond to DNS queries—basically, they help translate human-readable domain names into IP addresses that computers use to communicate.
Think of them as the “phonebooks of the Internet.”
💡 What is Hop in Networking 💡
In the context of DNS (or networking in general), the term “hop” refers to a step or intermediate point that a network packet passes through on its way from the source to the destination. Let’s clarify this in the context of DNS:
1. Hop in Networking
Every time a packet moves from one router or server to another in the network, it counts as one hop.
Hops are usually counted using tools like
traceroute
(Linux/macOS) ortracert
(Windows).
2. Hop in DNS Context
When a DNS resolver queries for a domain name:
Your computer asks the local DNS resolver (often your ISP or a public DNS like 8.8.8.8). (1st hop)
If the resolver doesn’t know the answer, it queries a root DNS server. (2nd hop)
The root server points it to a TLD server (like
.com
). (3rd hop)The resolver then queries the authoritative DNS server for the domain. (4th hop)
Each of these steps can be considered a hop, representing how far the query has traveled through the DNS hierarchy.
3. Why “Hops” Matter in DNS
Performance: More hops can mean slower response times.
Troubleshooting: Counting hops can help identify where DNS queries are delayed or failing.
Caching: To reduce hops, DNS resolvers cache answers so they don’t have to go through the full chain every time.
In short: A hop in DNS terms is each step a DNS query takes between servers from your computer to the authoritative DNS server.
💡 What is CNAME 💡
A CNAME stands for Canonical Name record in DNS. It’s a type of DNS record that maps one domain name to another domain name instead of mapping directly to an IP address.
Key Points about CNAME
Purpose
To create an alias for another domain name.
Useful when you want multiple domain names to point to the same IP indirectly, without maintaining separate A records.
How it Works
Suppose you have:example.com
→ IP192.168.1.10
(A record)You want
www.example.com
to point toexample.com
You can create a CNAME record:
www IN CNAME example.com
- When someone queries
www.example.com
, DNS automatically resolves it toexample.com
, which then resolves to192.168.1.10
.
Rules/Limitations
A CNAME must always point to another domain name, not directly to an IP.
You cannot have other DNS records (like A or MX) for the same name that has a CNAME.
Useful for subdomains like
mail.example.com
,shop.example.com
, etc.
Example Use Cases
Pointing
www
to the root domain.Using third-party services (like Shopify, GitHub Pages, or email services) where they provide a canonical domain to point your subdomain to.
In short: A CNAME record is like saying:
“This domain is an alias of that domain.”
DNS will follow the alias until it reaches the final IP address.
💡 What is NS Records 💡
An NS record in DNS stands for Name Server record.
It specifies which DNS server is authoritative for a particular domain or subdomain.
In other words, it tells the Internet which server knows the “official” information about a domain.
Key Points about NS Records
Purpose
Directs queries for a domain to the authoritative DNS servers.
Ensures that anyone trying to resolve your domain knows which server to ask for the official IP addresses.
How it Works
Suppose your domain isexample.com
. You might have NS records like:example.com. IN NS ns1.example.com. example.com. IN NS ns2.example.com.
When someone wants to look up
www.example.com
, their DNS resolver first checks the root → TLD → authoritative server.The NS record tells the resolver, “Ask
ns1.example.com
orns2.example.com
for details aboutexample.com
.”
Important Notes
Usually, a domain has at least two NS records for redundancy.
NS records can point to a subdomain (like
ns1.example.com
) or another domain entirely.NS records are different from A records: NS points to a server, A points to an IP address.
Example Use Case
You register a domain with a registrar. They ask you which DNS servers to use. Those servers are set as the NS records.
You can delegate a subdomain to another DNS server by creating NS records for that subdomain:
shop.example.com. IN NS ns1.shopprovider.com.
In short:
An NS record tells the world which DNS servers are responsible for handling a domain’s DNS queries. It’s like pointing to the official “phonebook office” for your domain.
💡 Important DNS Files 💡
Both /etc/resolv.conf
and /etc/hosts
are crucial for DNS and hostname resolution in Linux/Unix systems.
1. /etc/resolv.conf
Role
It tells your system which DNS servers to use to resolve domain names into IP addresses.
Acts as a configuration file for the resolver library, which programs use to translate domain names.
Typical Contents
Example:
nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com
options timeout:2 attempts:3
nameserver <IP>
→ Specifies the DNS server IP(s) to query.search <domain>
→ Default domain appended when resolving unqualified hostnames (like justhost1
instead ofhost1.example.com
).options
→ Additional settings like timeout or number of retries.
Importance
Without a properly configured
/etc/resolv.conf
, your system cannot resolve domain names (e.g.,ping
google.com
will fail, butping 142.250.190.14
will work).It’s critical for network apps that use domain names (web browsers, package managers, SSH, etc.).
Usage
Programs automatically read it when performing DNS lookups.
Example test:
cat /etc/resolv.conf
ping google.com
- You can temporarily edit it to use a different DNS server:
sudo nano /etc/resolv.conf
nameserver 1.1.1.1
2. /etc/hosts
Role
It is a local static mapping file for hostname ↔ IP resolution.
Before querying DNS, the system checks
/etc/hosts
first.Useful for overriding DNS or providing mappings when DNS is unavailable.
Typical Contents
Example:
127.0.0.1 localhost
192.168.1.10 server1.example.com server1
192.168.1.20 server2.example.com server2
Left side: IP address.
Right side: hostname(s) for that IP. The first name is canonical; others are aliases.
Importance
Provides fast hostname resolution without querying DNS.
Useful for:
Local testing (
127.0.0.1 mysite.local
)Temporary overrides
Internal network mapping without a DNS server
Usage
- Example test:
ping server1
ping server2.example.com
- You can add entries manually to map names to IPs for testing or internal networking.
Summary: Key Differences
Feature | /etc/resolv.conf | /etc/hosts |
Purpose | Configure which DNS servers to query | Map IP ↔ hostname locally |
Resolution Type | Dynamic / network-based | Static / local |
Checked First? | After /etc/hosts | First in lookup |
Typical Use | Internet / corporate DNS lookup | Local testing, overrides, small networks |
Editable? | Yes, but often auto-generated by network manager | Yes, manually by admin |
✅ In short:
/etc/hosts
→ Quick local hostname to IP mapping./etc/resolv.conf
→ Tells the system which DNS server to ask for domain name resolution.
Subscribe to my newsletter
Read articles from Sanket Nankar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
