Skip to main content

Command Palette

Search for a command to run...

Exploring Different Types of DNS Records: A Complete Overview

Updated
10 min read
Exploring Different Types of DNS Records: A Complete Overview

Let’s start with a simple but important question

How does a browser know where a website lives?

Have you ever wondered how, when you type something like google.com into your browser, it magically knows where to find Google's servers to show you the webpage?

It's not magic, it's the Domain Name System, or DNS!

Think of DNS as the internet's phonebook, but much more powerful. Just like you know your friend's name but not their exact house coordinates, the internet knows a website's name (like chaicode.com) but needs to find its numerical address (like 76.76.21.21) to send your request there. That numerical address is called an IP address.

What DNS Is (Explained in Very Simple Terms)

At its core, DNS is a hierarchical and distributed naming system for computers, services, or any resource connected to the internet or a private network. It translates human-readable domain names (like youtube.com) into machine-readable IP addresses (like 142.250.190.78). Without DNS, you'd have to remember a string of numbers for every website you wanted to visit – not very user-friendly!

Analogy: Imagine the internet as a massive city. Every building (server) has a unique street address (IP address). DNS is the city's comprehensive phonebook. You look up a business by its name, and the phonebook gives you its street address.

Why DNS Records Are Needed

DNS records are the individual entries within this "internet phonebook." They are small pieces of data that tell the DNS servers what to do with a domain name. Each type of record serves a specific purpose, directing different kinds of internet traffic (like website requests, emails, or security checks) to the correct destination. Without these records, your domain name wouldn't know where to send website visitors, emails, or anything else!

They are like specific instructions in our city phonebook. When someone asks "Where is Google's website?" or "Where should I send an email for ChaiCode?", these records provide the precise answers.

Now, let's break down the most common types of DNS records you'll encounter as a web developer.


What an NS Record Is (Who Is Responsible for a Domain)

  • Problem it solves: How does the internet know which specific DNS server holds the "phonebook" for your domain?

  • What it does in simple terms: An NS (Name Server) record tells the internet which DNS servers are authoritative for a domain. These are the servers that contain all the official DNS records for your website. It's like delegating responsibility for managing your domain's entries.

  • Real-life analogy: In our city analogy, if a friend asks you for example.com's address, and you don't have it, you might ask the "post office district manager" for the .com zone. That manager then points you to the specific "local post office" that handles all mail and addresses for example.com. The NS record is that pointer to the local post office. You might have seen them like ns1.cloudflare.com and ns2.cloudflare.com if you use Cloudflare for your domain management.


What an A Record Is (Domain → IPv4 Address)

  • Problem it solves: How do you get from a human-friendly domain name to the specific numerical IP address of a server that hosts your website?

  • What it does in simple terms: An A (Address) record maps a domain name (like example.com) directly to an IPv4 address (like 192.0.2.1). This is the most fundamental record for making your website accessible.

  • Real-life analogy: This is the most direct entry in our phonebook. You look up "Pizza Palace," and the phonebook tells you its exact street address: "123 Main Street." If piyushgarg.dev had an A record, it might directly point to 76.76.21.21 .


What an AAAA Record Is (Domain → IPv6 Address)

  • Problem it solves: IPv4 addresses are running out! IPv6 is the next generation of internet addressing, and websites need a way to be found via these new, longer addresses. This also addresses "Why IPv6 exists".

  • What it does in simple terms: An AAAA (quad-A) record is just like an A record, but it maps a domain name to an IPv6 address. IPv6 addresses are much longer and more complex (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334).

  • Real-life analogy: If some houses in our city get brand new, super-long, advanced addresses, the AAAA record is how the phonebook lists those. It's still an exact address, just in a new format.


What a CNAME Record Is (One Name Pointing to Another Name)

  • Problem it solves: Sometimes you want multiple subdomains (like blog.example.com or shop.example.com) to point to the same server, or to a service hosted elsewhere (like hashnode.network for a blog), without needing to hardcode IP addresses everywhere.

  • What it does in simple terms: A CNAME (Canonical Name) record creates an alias. It points one domain name to another domain name, not directly to an IP address. The internet then looks up the IP address of the second domain name.

  • Real-life analogy: Imagine "Bob's Blog" is a shop at "123 Main Street." If you look up "Bob's Blog" in the phonebook, it might say, "See 'Bob's Main Store'." You then look up "Bob's Main Store" and find "123 Main Street." During the cohort, we saw how blog.piyushgarg.dev used a CNAME to hashnode.network . This is perfect for when Hashnode or Vercel manages the actual server's IP address and it might change.

Gentle Clear Common Beginner Confusions: A Record vs. CNAME

FeatureA Record (Address)CNAME Record (Canonical Name)
Points ToAn IP address (IPv4)Another domain name
UsageDirect mapping of a domain to a server's IPCreating aliases for domains, often for subdomains or external services
FlexibilityLess flexible if the IP changes (requires manual update)More flexible; if the target domain's IP changes, your CNAME automatically follows
RestrictionsA domain can have an A record for its root (e.g., example.com)A root domain (e.g., example.com) generally cannot be a CNAME; it must be an A or AAAA record. Only subdomains (e.g., www.example.com, blog.example.com) typically use CNAMEs


What an MX Record Is (How Emails Find Your Mail Server)

  • Problem it solves: When someone sends an email to you@example.com, how does the internet know where example.com's email server is, as opposed to its website server?

  • What it does in simple terms: An MX (Mail Exchange) record tells other mail servers where to send emails for your domain. It specifies the mail servers that handle incoming email for your domain and their priority. You contributed this answer during the webinar chat regarding TXT records and email security.

  • Real-life analogy: Back to our city. If you want to send a letter to "Pizza Palace," the phonebook doesn't just give you the street address of the restaurant; it also gives you the address of the "mailroom building" specifically designed to receive and sort all their letters. The MX record is that special mailroom address.

Gentle Clear Common Beginner Confusions: NS Record vs. MX Record

FeatureNS Record (Name Server)MX Record (Mail Exchange)
PurposeSpecifies which servers manage all DNS records for your domain (the "master phonebook keeper")Specifies which servers handle email for your domain (the "email post office")
RoleDNS Delegation and managementEmail routing
Examplens1.example.com (tells where to find DNS data)mail.example.com (tells where to send emails)


What a TXT Record Is (Extra Information and Verification)

  • Problem it solves: You often need to add arbitrary text information to your domain's DNS for various purposes, like verifying domain ownership for a service or for email security (like SPF and DKIM).

  • What it does in simple terms: A TXT (Text) record lets you store any arbitrary text string in your DNS. It's primarily used for verification and security protocols. For instance, SPF (Sender Policy Framework) records, which help prevent email spoofing, are stored as TXT records. You mentioned this in the webinar when asked why TXT records exist.

  • Real-life analogy: This is like a small, official "sticky note" attached to your phonebook entry, or a "notice board" outside your house. It contains specific, verifiable information, like "This house is officially owned by [Your Name]" or "Deliveries for this address should follow security protocol XYZ." Services like Google Workspace or Mailchimp often ask you to add specific TXT records to prove you own your domain.


How All DNS Records Work Together for One Website

When you enter example.com into your browser, a sequence of events happens, orchestrating all these records:

  1. Your computer asks a local DNS resolver (often provided by your internet provider) for example.com's IP address.

  2. The resolver starts its "scavenger hunt," asking the Root DNS Servers, which direct it to the TLD Servers (for .com).

  3. The TLD servers then use the NS record to point the resolver to example.com's Authoritative Name Servers. These are the "master phonebook keepers" for your specific domain.

  4. The authoritative name server looks up example.com. If it has an A record (or AAAA record) for example.com, it provides the IP address, and your browser connects to the web server.

  5. If you try to access blog.example.com, the authoritative name server might have a CNAME record for blog.example.com that points to hashnode.network. The resolver then goes back and finds the A record for hashnode.network to get its IP.

  6. If you send an email to you@example.com, your mail server performs a DNS lookup specifically for the MX record of example.com, which directs it to example.com's mail server.

  7. During this email exchange, the recipient's mail server might check the TXT records (like SPF or DKIM) of your domain to verify the email's legitimacy.

It's a beautiful, intricate dance where each record plays its part!


A Complete DNS Setup for a Small Website (Example)

Let's imagine you have a website myawesomestartup.com hosted on a server with IPv4 address 198.51.100.10 and IPv6 address 2001:0db8::1234, and you use Google Workspace for email. You also have a blog at blog.myawesomestartup.com hosted on Hashnode. Your authoritative name servers are managed by Cloudflare.

Here’s what your DNS records might look like:

Record TypeNameValuePriority (for MX)Purpose
NSmyawesomestartup.comfelipe.ns.cloudflare.comN/ASpecifies Cloudflare as authoritative DNS.
NSmyawesomestartup.comluciana.ns.cloudflare.comN/ASecond Cloudflare nameserver.
Amyawesomestartup.com198.51.100.10N/APoints the main domain to your web server.
AAAAmyawesomestartup.com2001:0db8::1234N/APoints the main domain to your web server (IPv6).
CNAMEwww.myawesomestartup.commyawesomestartup.comN/Awww points to your main domain.
CNAMEblog.myawesomestartup.comhashnode.networkN/ABlog subdomain points to Hashnode.
MXmyawesomestartup.comaspmx.l.google.com1Primary Google mail server.
MXmyawesomestartup.comalt1.aspmx.l.google.com5Secondary Google mail server.
TXTmyawesomestartup.comv=spf1 include:_spf.google.com ~allN/ASPF record for email security.
TXT_dmarc.myawesomestartup.comv=DMARC1 p=none fo=1N/ADMARC record for email authentication.
TXTgoogle._domainkey.myawesomestartup.comv=DKIM1 k=rsa...N/ADKIM record for email digital signatures.

Conclusion

Phew! That might seem like a lot to take in, but don't feel overwhelmed. DNS looks complex initially because of the many record types and their interconnectedness. However, as we've seen, each record solves a very specific problem and, once understood step by step, makes perfect sense. You've already engaged with these concepts, like TXT records for email security and CNAMEs for connecting your blog, during the cohort discussions.

Keep learning and experimenting. With every website you build or every domain you configure, these fundamental networking concepts will become second nature. You've got this!