DEV Community

sanjeev singh
sanjeev singh

Posted on

DNS Records Explained: The Internet's Address Book

How Does a Browser Know Where a Website Lives?

You type google.com into your browser and—boom—Google appears. But have you ever wondered how your browser knows where to find Google's servers among billions of devices on the internet?

The answer is DNS (Domain Name System), and today we're going to understand how it works in the simplest way possible.

What is DNS?

Think of DNS as the phonebook of the internet.

When you want to call your friend, you don't memorize their phone number—you just look up their name in your contacts. Similarly, when you want to visit a website, you don't need to remember its IP address (something like 142.250.185.46). You just type the domain name (google.com), and DNS translates it into the IP address for you.

You: "I want google.com"
       ↓
DNS: "That's at 142.250.185.46"
       ↓
Browser: *connects to 142.250.185.46*
       ↓
Google appears! 🎉
Enter fullscreen mode Exit fullscreen mode

Why Do We Need DNS Records?

A domain name is more than just a website address. It needs to handle:

  • Web traffic (showing your website)
  • Email delivery (sending and receiving emails)
  • Subdomains (like blog.example.com or shop.example.com)
  • Verification (proving you own the domain)

DNS records are like instructions that tell the internet how to handle all these different tasks for your domain.


The Main DNS Record Types

Let's explore the most important DNS records one by one, understanding what problem each one solves.

1. NS Record (Name Server Record)

The Problem: Who is in charge of this domain?

The Solution: NS records tell the internet which name servers are responsible for your domain.

Think of it like this: When you buy a domain, you need to tell the internet, "Hey, for all questions about example.com, ask these specific servers." Those servers are your name servers.

Real-life example:

Domain: example.com
NS Records:
  - ns1.cloudflare.com
  - ns2.cloudflare.com
Enter fullscreen mode Exit fullscreen mode

This means Cloudflare's servers are responsible for storing and managing all DNS records for example.com.

Simple Analogy: NS records are like saying, "For any questions about my house, ask the property management company at this address."


2. A Record (Address Record)

The Problem: Where is your website located?

The Solution: A records map your domain name to an IPv4 address (the most common type of IP address).

This is the most fundamental DNS record. It directly answers the question: "What's the IP address for this domain?"

Real-life example:

example.com  →  192.0.2.1
Enter fullscreen mode Exit fullscreen mode

When someone types example.com in their browser, the DNS system looks up the A record and finds 192.0.2.1, then connects to that server.

Simple Analogy: A records are like your home address. If someone wants to visit you, they need to know the exact street address.

Diagram:

Browser asks: "Where is example.com?"
       ↓
DNS looks up A Record
       ↓
A Record says: "192.0.2.1"
       ↓
Browser connects to server at 192.0.2.1
       ↓
Website loads!
Enter fullscreen mode Exit fullscreen mode

3. AAAA Record (Quad-A Record)

The Problem: What if your server uses the newer IPv6 addressing system?

The Solution: AAAA records map your domain to an IPv6 address.

IPv6 is the newer version of IP addresses that looks like this: 2001:0db8:85a3:0000:0000:8a2e:0370:7334. It was created because we're running out of IPv4 addresses (which are limited to about 4 billion).

Real-life example:

example.com  →  2001:db8::1
Enter fullscreen mode Exit fullscreen mode

Most modern websites have both A and AAAA records to support older and newer devices.

Simple Analogy: If A records are like your street address, AAAA records are like GPS coordinates—a different way to find the same place.


4. CNAME Record (Canonical Name Record)

The Problem: What if you want one domain name to point to another domain name?

The Solution: CNAME records create an alias from one domain to another.

This is super useful for subdomains. Instead of maintaining separate IP addresses, you can make a subdomain point to your main domain.

Real-life example:

blog.example.com  →  CNAME  →  example.com
Enter fullscreen mode Exit fullscreen mode

So when someone visits blog.example.com, the DNS system first follows the CNAME to example.com, then looks up the A record for example.com to find the IP address.

Simple Analogy: A CNAME is like saying, "For my nickname, just look up my real name." It's a redirect to another name, not a direct address.

Important Note: You can't use a CNAME for your root domain (example.com). CNAMEs only work for subdomains like www.example.com or blog.example.com.

Diagram:

User types: blog.example.com
       ↓
DNS finds CNAME: "This points to example.com"
       ↓
DNS looks up A record for example.com
       ↓
Finds IP: 192.0.2.1
       ↓
Website loads!
Enter fullscreen mode Exit fullscreen mode

5. MX Record (Mail Exchange Record)

The Problem: How do emails find your mail server?

The Solution: MX records tell the internet where to deliver emails for your domain.

When someone sends an email to hello@example.com, the sending server looks up the MX records for example.com to find out which mail server should receive the email.

Real-life example:

example.com  MX Records:
  - Priority 10: mail1.example.com
  - Priority 20: mail2.example.com
Enter fullscreen mode Exit fullscreen mode

The priority number determines which server to try first (lower numbers = higher priority). If the first server is down, the second one is tried.

Simple Analogy: MX records are like telling the post office, "All mail for my address should go to the mailbox at this specific post office."

Diagram:

Someone sends email to: hello@example.com
       ↓
Sending server checks MX records for example.com
       ↓
Finds: mail1.example.com (priority 10)
       ↓
Email delivered to mail1.example.com
       ↓
You receive the email!
Enter fullscreen mode Exit fullscreen mode

6. TXT Record (Text Record)

The Problem: How do you verify ownership or provide extra information about your domain?

The Solution: TXT records store text information for various purposes like verification, security, and email authentication.

TXT records are incredibly flexible. They're used for:

  • Verifying domain ownership (for services like Google Workspace)
  • Email security (SPF, DKIM, DMARC records)
  • Site verification (for search engines)
  • General information about your domain

Real-life example:

example.com  TXT  "v=spf1 include:_spf.google.com ~all"
Enter fullscreen mode Exit fullscreen mode

This TXT record tells email servers, "Only Google's servers are allowed to send email on behalf of example.com."

Simple Analogy: TXT records are like sticky notes you can attach to your domain, containing extra instructions or verification codes.


How DNS Records Work Together

Here's the beautiful part: all these records work together to make your website and email function properly. Let's see a complete example:

Example: Setting up "example.com"

NS Records:
  example.com  →  ns1.hosting.com
  example.com  →  ns2.hosting.com
  (These tell the internet who manages the DNS)

A Record:
  example.com  →  192.0.2.1
  (This is where the website lives)

AAAA Record:
  example.com  →  2001:db8::1
  (IPv6 address for the website)

CNAME Records:
  www.example.com  →  example.com
  blog.example.com  →  example.com
  (Subdomains point to the main domain)

MX Records:
  example.com  →  Priority 10: mail.example.com
  (This is where emails go)

TXT Records:
  example.com  →  "v=spf1 mx ~all"
  (Email security settings)
Enter fullscreen mode Exit fullscreen mode

What happens when someone visits your website:

  1. They type www.example.com
  2. DNS looks up the CNAME → finds it points to example.com
  3. DNS looks up the A record for example.com → finds 192.0.2.1
  4. Browser connects to 192.0.2.1
  5. Website loads!

What happens when someone sends you an email:

  1. They send to hello@example.com
  2. Sending server looks up MX records
  3. Finds mail.example.com with priority 10
  4. Looks up A record for mail.example.com
  5. Delivers email to that mail server

Common Beginner Confusions (Cleared Up!)

A Record vs CNAME

When to use A Record:

  • When you want to point directly to an IP address
  • For your root domain (example.com)

When to use CNAME:

  • When you want to point to another domain name
  • For subdomains (www.example.com, blog.example.com)

Remember: CNAME is a nickname that points to a name. A Record is a name that points to an address.

NS Record vs MX Record

NS Records: Tell the internet who manages ALL DNS records for your domain.

MX Records: Tell the internet where to send emails for your domain.

Think of NS as "who's in charge of everything" and MX as "where the mailbox is located."


Quick Visual Summary

┌─────────────────────────────────────────────────┐
│           DNS Records for example.com           │
├─────────────────────────────────────────────────┤
│                                                 │
│  NS Records (Authority)                        │
│  ↳ Who manages this domain?                    │
│                                                 │
│  A Record (Website IPv4)                       │
│  ↳ example.com → 192.0.2.1                     │
│                                                 │
│  AAAA Record (Website IPv6)                    │
│  ↳ example.com → 2001:db8::1                   │
│                                                 │
│  CNAME Records (Aliases)                       │
│  ↳ www.example.com → example.com               │
│  ↳ blog.example.com → example.com              │
│                                                 │
│  MX Records (Email)                            │
│  ↳ mail.example.com (Priority 10)              │
│                                                 │
│  TXT Records (Verification & Security)         │
│  ↳ "v=spf1 mx ~all"                            │
│                                                 │
└─────────────────────────────────────────────────┘
Enter fullscreen mode Exit fullscreen mode

Final Thoughts

DNS might seem complicated at first, but once you understand that each record type solves a specific problem, it all makes sense:

  • NS: Who's in charge?
  • A/AAAA: Where's the website?
  • CNAME: What's the nickname?
  • MX: Where's the mailbox?
  • TXT: What's the extra info?

The next time you type a web address, you'll know there's an entire system working behind the scenes, translating names to numbers and routing your request to the right place.

Top comments (0)