Skip to main content
1:1 mock interviews with Sumit, scored on a real hiring rubric.Book a slot →

How DNS Works: From Domain Name to IP Address

Understand how DNS resolves domain names: resolvers, root, TLD and authoritative servers, caching and TTL, record types and debugging with dig.

JioCoderUpdated Oct 11, 20262 min readNetworking
How DNS Works: From Domain Name to IP Address

DNS (Domain Name System) translates human-friendly names like jiocoder.com into IP addresses that computers use. Almost every network request you make starts with a DNS lookup.

The players in a DNS lookup#

  • Stub resolver – the small DNS client in your OS or browser.
  • Recursive resolver – usually run by your ISP or a public provider (like 1.1.1.1 or 8.8.8.8). It does the hard work of finding the answer.
  • Root name servers – the top of the hierarchy. They know where each top-level domain lives.
  • TLD name servers – responsible for .com, .in, .org and so on.
  • Authoritative name servers – hold the actual records for a domain.

A lookup, step by step#

DNS lookup sequence: browser asks resolver, which queries root, TLD and authoritative name servers
  1. Your browser asks the recursive resolver: "What's the IP of jiocoder.com?"
  2. If not cached, the resolver asks a root server, which replies with the addresses of the .com TLD servers.
  3. The resolver asks a .com TLD server, which replies with the domain's authoritative name servers.
  4. The resolver asks the authoritative server, which returns the A (or AAAA) record.
  5. The resolver caches the answer and returns it to your browser, which then opens a connection to that IP.

The resolver's queries are iterative (each server points to the next), while your browser's query to the resolver is recursive (it expects a final answer).

Caching and TTL#

Every DNS record has a TTL (time to live) in seconds. Browsers, operating systems and resolvers cache answers until the TTL expires. That's why most lookups are answered in milliseconds – and why DNS changes can take time to "propagate".

Tip

Planning a server migration? Lower the TTL (e.g. to 300 seconds) a day before the change, then raise it again once everything is stable.

Common DNS record types#

Common DNS record types: A, AAAA, CNAME, MX, NS, TXT, SOA, PTR, SRV and CAA
RecordPurposeExample
AName → IPv4jiocoder.com → 203.0.113.5
AAAAName → IPv6jiocoder.com → 2001:db8::5
CNAMEAlias to another namewww → jiocoder.com
MXMail server for the domain10 mail.jiocoder.com
TXTFree text: SPF, DKIM, domain verificationv=spf1 include:... ~all
NSAuthoritative name serversns1.provider.net

Debugging DNS from the terminal#

Bash
# Basic lookup
dig jiocoder.com

# Only the answer
dig +short jiocoder.com

# Specific record type
dig MX gmail.com
dig AAAA google.com

# Follow the full chain from the root
dig +trace jiocoder.com

# Ask a specific resolver
dig @1.1.1.1 jiocoder.com

DNS security in brief#

  • DNS spoofing / cache poisoning – an attacker injects fake answers into a resolver's cache.
  • DNSSEC – signs records so resolvers can verify they're authentic.
  • DoH / DoT – DNS over HTTPS or TLS encrypts queries so others on the network can't read or tamper with them.

Key takeaways#

  • DNS maps names to IP addresses through a hierarchy: root → TLD → authoritative.
  • Recursive resolvers do the lookup work and cache results.
  • TTL controls how long answers are cached.
  • A, AAAA, CNAME, MX and TXT are the records you'll use most.
  • dig is your best friend for DNS debugging.