DNS
Domain Name Service translate domain names (like www.google.com
) to its IP addresses. DNS managed globally by ICANN (Internet Corporation for Assigned Names and Numbers).
Why we need DNS
-
Every device or web servers on the internet has a unique IP address. We need these IP addresses to route data and communicate with each other. However, IPs are complex numbers like
142.250.182.206
, which are hard to remember. So, we map these IP addresses to domain names, which are easier to read, remember and type. -
IP addresses are not static and may change dynamically. So, a mapping is required.
How DNS Works

-
Local cache like browsers or OS cache is checked first. If IP is already known, then no external loopkup is needed.
-
If IP is not cached by local cache, the request goes to DNS resolver (also called Recursor, beacuse it keeps asking for IP recursively untile it gets the one). It usually provided by Internet Service Provider(ISP), or external services like Google :
8.8.8.8
, Cloudflare:1.1.1.1
. -
DNS resolver also has cache. If it finds the mapping (domain to IP) in its cache, it returns the result. If not then it forwars the request to the Root Nameserver.
-
A Root Nameserver is the starting point of the DNS hierarchy. There are 13 root servers (A to M) in the world, each replicated globally. The Root Nameserver directs the resolver to the correct TLD (Top Level Domain like
.com
,.in
,.ai
,.io
etc.). -
The TLD Server responds with the location of the Authoritative Name Server. The resolver then queries this server to retrieve the final DNS record. Usually an
A record
which contains the IP address of the requested domain.
TLD Server Know Where the Authoritative Name Server Is?
When we buy a domain name (like example.com
) from a domain provider (e.g. - GoDaddy), we are required to set the authoritative nameservers for that domain. These nameservers are registered with the TLD server.
- Assume, A person buy a domain
example.com
from a domain provider, and set the nameservers likens1.myhosting.com
,ns2.myhosting.com
. - Now domain provider updates TLD servers for example -
.com
TLD server stores :example.com → ns1.myhosting.com
Important
- DNS itself isn't secure by default. For security purpose, DNSSEC used, which is signed DNS record.
- DNS uses UDP protocol at the Transport layer bacause -
- UDP is faster than TCP because it has no three way handshake connection setup.
- Although UDP is not reliable by default, reliability can be implemented at the application layer. This can be achieved by using timeouts and retransmitting the request if no response is received.
- UDP is lightweight and adds minimal overhead compared to TCP.
- A typical DNS query and its response usually fit within the 512-byte limit of a single UDP packet.
- But there is an exception. If the DNS response is too large (e.g., with DNSSEC), or if reliability is required, DNS can fall back to TCP protocol.