DEV Community

Cover image for Everything You Need To Know About DNS (Domain Name System)
Masudur Rahman Sourav
Masudur Rahman Sourav

Posted on

Everything You Need To Know About DNS (Domain Name System)

Imagine trying to memorize the phone number of every person you’ve ever met. Instead, you use a contacts app you type "Jhon," and your phone dials 555-0199. The Domain Name System (DNS) is the internet's contacts app. It translates human-friendly domain names (like netflix.com) into the machine-friendly IP addresses (like 192.0.2.1) that computers use to route data globally.

The Real-World Analogy: Navigating a Mega-City
Think of finding a website like searching for a specific specialty store in a massive, unfamiliar city:

Local Cache: First, you check your own pockets (Browser or OS cache) to see if you have the address written down from a previous visit.

Recursive Resolver: If you don't, you ask a local hotel concierge ( ISP ) to find it for you.

Root Server: The concierge doesn't know, so they call the city's central directory. The central directory points them to the commercial district manager.

TLD Server: The district manager (who handles all .com commerce) points the concierge to the building's specific property manager.

Authoritative Server: The property manager checks their official tenant ledger and gives the concierge the exact suite number.

The DNS resolution journey. Source: GodfriedEdelman / Getty Images

1.Check Local Cache:Browser and OS Level.

Before asking the internet, your browser checks its own memory. If the IP isn't there, it asks your computer's Operating System cache. If you've visited the site recently, the journey ends here in milliseconds.

2.Query the Recursive Resolver:Usually your ISP.

If the OS doesn't know, it sends the request to a DNS Resolver (often run by your Internet Service Provider, or a public one like Google's 8.8.8.8). This server acts as your personal detective, taking on the heavy lifting of tracking down the IP address.

3.Ask the Root Server:The top of the internet hierarchy.

The resolver asks one of the 13 logical Root Name Servers worldwide. The root server doesn't know the exact IP, but it reads the very end of your URL (the .com or .org part) and directs the resolver to the correct Top-Level Domain server.

4.Ask the TLD Server:Top-Level Domain Manager.

The resolver now queries the specific .com TLD server. This server manages all .com domains globally. It checks its records for your specific domain name (e.g., netflix.com) and points the resolver to the domain's Authoritative Name Server.

5.Query the Authoritative Name Server:The final answer.

The resolver reaches the Authoritative Name Server (managed by whoever hosts the domain's DNS, like AWS Route53 or Cloudflare). This server holds the exact, official DNS records. It hands over the final IP address.

6.Return and Cache:Speeding up future visits.

The resolver returns the IP address to your web browser so it can load the page. Crucially, the resolver, your OS, and your browser all save (cache) this answer for a set period known as the Time-to-Live (TTL)—to skip this entire process next time.

The DNS Record Toolkit

The DNS Record Toolkit

Why System Designers & Software Engineers Must Master DNS

To an everyday user, DNS is just a lookup tool. To a system designer, DNS is the frontline traffic cop of a global architecture.

Global Load Balancing and Latency DNS isn't static. Advanced DNS setups use geolocation routing to analyze where a user is calling from. If a user in Tokyo requests your app, DNS can intelligently hand them the IP address of your Japanese data center, while giving a New York user the IP of your US East data center. This slashes latency before the user even connects to a server.

High Availability and Failover If a hurricane takes out your primary data center, your app goes down. An engineer with strong DNS knowledge will configure automated health checks and failover routing. If the primary IP stops responding, the DNS server instantly stops giving out that IP and seamlessly redirects all new traffic to a backup facility.

The TTL Trap (Time-to-Live) Every DNS record has a TTL—a timer dictating how long devices should cache the answer. If a system designer is planning a major server migration but leaves the TTL set to 24 hours, users' browsers will stubbornly try to connect to the old, dead server for a full day. Mastering TTL is the difference between a zero-downtime migration and a catastrophic outage.

Microservice Discovery Inside modern cloud applications, hundreds of tiny, independent services (like a payment service and a shopping cart service) need to talk to each other. Because containers spin up and down constantly, their internal IP addresses change by the minute. Internal DNS allows "Service A" to find "Service B" simply by calling its name, completely abstracting away the chaotic IP swapping underneath.

Security Posture DNS is a major attack vector. Attackers use "DNS Spoofing" (cache poisoning) to trick a resolver into saving a fake IP address, silently redirecting your users to a malicious clone of your app. Engineers must understand how to implement DNSSEC (DNS Security Extensions) to cryptographically sign their records, guaranteeing users are truly talking to the authoritative source.

Security

Imagine a world where anyone could swap out the street signs in your neighborhood. You try to drive to your bank, but a fake sign directs you to a perfect replica of the bank run by thieves. That’s the exact vulnerability built into the original design of DNS.

Because DNS was built in the 1980s an era of high trust and low security it assumed every answer it received was honest. Today, system designers and engineers must build defenses against this assumption.

The Threat: DNS Spoofing (Cache Poisoning)

When your local resolver (like your ISP) asks the internet for the IP address of mybank.com, it waits for a response. In a DNS Spoofing attack, a hacker races to answer the resolver before the legitimate authoritative server can.

If the hacker wins the race, they hand the resolver a fake IP address pointing to their malicious server. Worse, the resolver caches (memorizes) this fake answer. Now, every single person using that ISP who types in mybank.com is silently redirected to the hacker's fake login page.

DNS spoofing tricks resolvers into caching fake IP addresses.. Source: bsd studio / Getty Images

The Shield: DNSSEC (DNS Security Extensions)

To stop someone from forging street signs, you need a way to prove who put the sign there. DNSSEC acts like a digital wax seal on every DNS answer.

Instead of just returning the IP address (the A Record), a DNSSEC-enabled server returns the IP address and a cryptographic signature (the RRSIG record).

Here is how the chain of trust works:

The Zone Signing Key (ZSK): Your DNS provider uses a private key to mathematically sign your DNS records.

The Key Signing Key (KSK): To prove the ZSK is legitimate, a stronger key (the KSK) signs the ZSK.

The Chain of Trust: Your KSK is verified by the Top-Level Domain (like .com), which is verified by the Root Server.

When a user's resolver receives the answer, it uses public keys to verify the signature. If a hacker tries to spoof the answer, they won't have your private key. The signature will fail, the resolver will reject the fake IP, and the user is protected.

Engineering Reality Check: Implementing DNSSEC isn't a simple toggle switch. It requires careful key management. If your keys expire or roll over incorrectly, resolvers will reject your legitimate records, effectively deleting your website from the internet.

How DNS handles load balancing?

If you build a blazing-fast application but host it exclusively in New York, a user in Tokyo will still experience a sluggish, frustrating delay. The speed of light is a hard physical limit, and every network hop adds latency.

To solve this, system designers deploy applications globally and use two powerful DNS techniques to ensure users are always connected to the server closest to them: Geographic Routing and DNS Anycast.

1. Geographic Routing (Geo-DNS): The Smart Operator

Think of Geo-DNS like calling a national pizza delivery number. You dial one central number, but the system looks at your area code and connects you to the specific franchise five minutes from your house.

Instead of an area code, Geo-DNS looks at the IP address of the user's recursive resolver.

When the DNS query reaches your authoritative server, the server doesn't just hand out a static answer. Instead, it:

Compares the user's IP against a massive, continuously updated GeoIP database.

Determines the user is located in Tokyo.

Looks at your routing policy and returns the specific IP address of your Tokyo data center, rather than your New York or London facilities.

This happens at the application logic layer of DNS. The DNS server is actively making a decision to hand out different answers (different IP addresses) based on who is asking.

2. DNS Anycast: The Network Illusion

If Geo-DNS is a smart operator handing out different addresses, Anycast is an illusion where multiple physical locations share the exact same address.

Think of the emergency number "911". There isn't just one giant 911 call center for the entire country. There are thousands. But you dial the exact same number everywhere, and the underlying phone network routes you to the closest one.

Anycast does this for IP addresses using the internet's core routing protocol, BGP (Border Gateway Protocol).

  • Unicast (Standard): One IP address points to exactly one physical server.
  • Anycast: Multiple physical servers across the globe announce to the internet that they are the destination for a single IP address (like Google's famous 8.8.8.8 DNS resolver).

Unicast vs. Anycast network topology. Source: Brandsec

When a user's computer sends a packet to an Anycast IP, the internet's core routers look at the map and simply send the packet down the shortest physical path. The user naturally hits the server closest to them without the DNS server needing to perform any GeoIP lookups.

Why Engineers Love Anycast for Security

Anycast isn't just about speed; it is the ultimate defense against Distributed Denial of Service (DDoS) attacks.

If a massive botnet tries to flood a Unicast IP with malicious traffic, that single server gets overwhelmed and dies. If a botnet attacks an Anycast IP, the malicious traffic from a compromised computer in Brazil goes to the Brazilian server, while the attack traffic from Germany goes to the German server. The attack is naturally fragmented and absorbed by your global edge network, rather than concentrating on a single point of failure.

Engineers Love Anycast for Security

How BGP Actually Calculates The Shortest Path?

The internet is not a single, giant cloud; it is a massive patchwork quilt of smaller, independent networks. These networks run by ISPs (like Comcast or Vodafone), tech giants (like Google or AWS), and large universities—are called Autonomous Systems (AS).

If you want to send data from an AS in London to an AS in Tokyo, you need a way to figure out which overlapping patches of the quilt to cross. That is exactly what BGP (Border Gateway Protocol) does. It is the postal sorting system of the internet.

BGP connecting two Autonomous Systems (AS). Source: PyNet Labs

How BGP Routes Traffic: The "AS Path"

nside your home network, your router uses protocols that measure connection speeds, bandwidth, or latency to find the fastest path. BGP does not care about any of that.

BGP is a Path Vector Protocol. Its primary metric for determining the "best" or "shortest" route is simply counting the number of Autonomous Systems the data has to jump through. This list of hops is called the AS_PATH.

  1. The Announcement: A router in AS-500 tells its neighbor, "Hey, I can reach IP address 1.1.1.1."
  2. The Propagation: That neighbor (AS-400) tells its neighbor, "I can reach 1.1.1.1, and the path is [AS-400, AS-500]."
  3. The Decision: Your local ISP router (AS-100) might receive two announcements for 1.1.1.1.

Your router looks at the AS_PATH length, sees that Path B has fewer hops, and updates its routing table to send all traffic for 1.1.1.1 toward AS-600.

BGP Meets Anycast: The Shortest Path Wins

In a standard setup, only one AS in the world announces a specific IP address. But in an Anycast setup (used by Cloudflare, AWS Route53, and Google DNS), multiple data centers across the globe announce the exact same IP address simultaneously.

Because BGP is fundamentally designed to find the shortest AS_PATH to a given destination, Anycast exploits this feature perfectly:

  • Data Center A (New York) announces it hosts 8.8.8.8.
  • Data Center B (Tokyo) announces it hosts 8.8.8.8.
  • Data Center C (London) announces it hosts 8.8.8.8.

When a user in Paris tries to reach 8.8.8.8, their ISP's BGP router looks at the global routing tables. It sees that the AS_PATH to London is only 2 hops, New York is 5 hops, and Tokyo is 8 hops. BGP automatically sends the Parisian user's traffic to London.

BGP Anycast Routing Simulator

Why Engineers Must Understand BGP

While Anycast and BGP provide incredible resilience, they rely on a system built in 1989 that operates entirely on "trust."

If an engineer misconfigures a BGP router in a small ISP in Brazil and accidentally announces, "I have a 1-hop path to Google's servers," the global internet might believe them. This is called a BGP Route Leak or BGP Hijacking. Traffic intended for Google will suddenly flood into that small Brazilian ISP, crashing their network and taking Google offline for millions of users.

Understanding BGP means understanding that the internet's core routing is a fragile web of trust, and deploying Anycast requires extreme care in how you announce your IP addresses to the global backbone.

How do we prevent BGP Hijacking?

BGP was built on a handshake system if a router claims it owns an IP address, the rest of the internet generally believes it. This trust model is what enables a BGP Hijack: a malicious (or misconfigured) network simply announces to the world, "I am the shortest path to Google's IP addresses." Without verification, global traffic blindly reroutes into the hijacker's network.

RPKI (Resource Public Key Infrastructure) is the cryptographic upgrade the internet needs to fix this. It replaces blind trust with mathematically verifiable proof of ownership.

How RPKI Secures the Route

Think of RPKI like a digital passport control for BGP route announcements.

Before an Autonomous System (AS) can legitimately announce an IP prefix to the internet, the true owner of that IP block must create a cryptographic certificate. This certificate is called a ROA (Route Origin Authorization).

A ROA explicitly states two things:

The IP Prefix: (e.g., 192.0.2.0/24)

The Origin AS: The exact Autonomous System Number (e.g., AS65005) authorized to announce it.

RPKI uses ROAs to authorize route origins.. Source: phoenixNAP

Route Origin Validation (ROV) in Action

When a major ISP (like Comcast or AT&T) runs a BGP router with RPKI enforced, it performs Route Origin Validation (ROV) on every announcement it receives.

Here is how the router filters the traffic:

  • Valid: The BGP announcement says AS65005 originates 192.0.2.0/24. The router checks the global RPKI database, finds a matching ROA, and accepts the route. Traffic flows normally.
  • Invalid (The Hijack): A malicious network, AS65002, suddenly announces 192.0.2.0/24. The router checks the RPKI database. The ROA says only AS65005 is allowed to announce those IPs. The router instantly marks the malicious announcement as Invalid and drops it. The hijack is blocked.
  • Unknown: If the IP owner hasn't created a ROA yet, the route is marked "Unknown." Most routers will still accept this to avoid breaking the internet, but they will prefer "Valid" routes if a conflict arises.

BGP Hijack & RPKI Protection Simulator

Why RPKI Matters to System Designers

For a software engineer or system designer, understanding RPKI is critical for protecting the application layer:

  1. DDoS Mitigation: Attackers often use BGP route leaks to sinkhole your traffic or overwhelm a small segment of your network. Registering your IPs with strict ROAs ensures that major transit providers will drop malicious reroutes before they impact your users.
  2. Compliance & Trust: If you are designing fintech, healthcare, or government systems, traffic interception is a catastrophic breach. RPKI guarantees that your data physically reaches the correct data center and isn't silently diverted to a rogue network for packet sniffing.
  3. The "Fat Finger" Defense: Most BGP leaks aren't malicious; they are typos by tired engineers. RPKI ensures that if an engineer at a regional ISP accidentally announces your IP space, the global internet will cryptographically reject the typo, preventing an accidental global outage.

How BGP Relates To CDNs?

Without a CDN, every single user across the globe has to travel to your one "Origin Server" (let's say, in New York) to fetch a website's images, videos, and HTML. A user in Sydney might wait 300 milliseconds just for the data to travel back and forth.

CDNs like Cloudflare, Fastly, and Akamai solve this by building hundreds of mini data centers called Points of Presence (PoPs) or Edge Servers—in almost every major city on Earth. They tie all of these servers together using BGP Anycast.

CDNs deploy hundreds of Edge servers globally, all sharing the same Anycast IP.. Source: goleiro35 / Getty Images

The CDN + Anycast Workflow

When you put your application behind a CDN, you configure your DNS so that yourwebsite.com resolves to an Anycast IP address provided by the CDN (e.g., 104.16.124.96).

Every single CDN Edge Server in the world announces to the internet that it is 104.16.124.96.

Here is exactly what happens when a user in Sydney types in your URL:

1.BGP Routes to the Edge:The Sydney user's ISP looks at the BGP routing tables. It sees that the shortest physical path to 104.16.124.96 is the CDN's Sydney Edge Server, not the one in New York or London. The user is instantly connected to a server in their own city.

2.Check the Cache (Cache Hit):Blazing fast response.The Sydney Edge Server checks its local hard drives: "Do I have a copy of yourwebsite.com/logo.png?" If another user in Sydney recently loaded that image, the Edge Server will have it saved (a Cache Hit). It sends the image to the user in 10 milliseconds. The request never even touches your New York server.

3.Contact the Origin (Cache Miss):Fetching the master copy.If the Sydney Edge Server does not have the image (a Cache Miss), it acts as a proxy. The Edge Server opens a dedicated, high-speed connection back to your New York Origin Server, fetches the image, sends it to the user, and saves a copy for the next person in Sydney.

A Cache Miss requires a trip to the Origin, but subsequent requests are served from the Edge.. Source: RocketCDN

Why System Designers Rely on CDNs

Deploying a CDN isn't just about making images load faster; it fundamentally changes the architecture and economics of scaling a global application.

Designers Rely on CDNs

Top comments (0)