DNS magic and internals

DNS magic and internals

Why DNS is Important

Imagine trying to remember the phone numbers of everyone you know instead of just their names. It would be quite challenging! DNS simplifies the process by allowing us to use memorable domain names instead of numerical addresses, ensuring a best online experience.

When you want to visit a website, you type in a domain name, such as "ChaiandCode.com," but computers communicate using IP addresses, which are numerical identifiers. DNS translates these names into IP addresses, making it easier for us to access websites without remembering complex numbers.

DNS Hierarchy: A Tree-like Structure

The DNS hierarchy can be visualized as a tree:

  1. Root Zone: The top of the hierarchy, managed by the Internet Corporation for Assigned Names and Numbers (ICANN).

  2. Top-Level Domains (TLDs): Such as .com, .org, .net, and country-specific domains like .us or .uk.

  3. Authoritative Servers: Hold the specific DNS records for each domain.

Types of DNS Records with google.com Examples

1. A Record (Address Record)

  • Purpose: Maps a domain name to an IPv4 address.

  • Example:

    Copy

      google.com.    A    142.250.193.174
    
    • This means google.com points to the IPv4 address 142.250.193.174.

2. AAAA Record (IPv6 Address Record)

  • Purpose: Maps a domain name to an IPv6 address.

  • Example:

    Copy

      google.com.    AAAA    2404:6800:4007:821::200e
    
    • This means google.com points to the IPv6 address 2404:6800:4007:821::200e.

3. CNAME Record (Canonical Name Record)

  • Purpose: Creates an alias for a domain name. It points one domain to another domain.

  • Example:

    Copy

      www.google.com.    CNAME    google.com.
    

4. MX Record (Mail Exchange Record)

  • Purpose: Specifies the mail server responsible for handling email for a domain.

  • Example:

    Copy

      google.com.    MX    10    aspmx.l.google.com.
    
    • This means emails sent to @google.com should be delivered to the mail server aspmx.l.google.com. The number 10 is the priority (lower numbers have higher priority).

5. TXT Record (Text Record)

  • Purpose: Stores text information for various purposes, such as email validation (SPF, DKIM) or domain ownership verification.

  • Example:

    Copy

      google.com.    TXT    "v=spf1 include:_spf.google.com ~all"
    
    • This is an SPF record used to prevent email spoofing. It tells email servers that only specific servers (like Google’s) are allowed to send emails for google.com.

6. NS Record (Name Server Record)

  • Purpose: Specifies the authoritative name servers for a domain.

  • Example:

    Copy

      google.com.    NS    ns1.google.com.
      google.com.    NS    ns2.google.com.
    

7. SOA Record (Start of Authority Record)

  • Purpose: Contains administrative information about the domain, such as the primary name server, the email of the domain administrator, and timers for refreshing the zone.

  • Example:

    Copy

      google.com.    SOA    ns1.google.com. dns-admin.google.com. (
                              2023101301 ; Serial number
                              3600       ; Refresh time
                              1800       ; Retry time
                              1209600    ; Expire time
                              86400 )    ; Minimum TTL
    

8. PTR Record (Pointer Record)

  • Purpose: Used for reverse DNS lookups, mapping an IP address to a domain name.

  • Example:

    Copy

      174.193.250.142.in-addr.arpa.    PTR    google.com.
    
    • This means the IP address 142.250.193.174 resolves to the domain name google.com.

9. SRV Record (Service Record)

  • Purpose: Specifies the location of a specific service, such as VoIP or instant messaging.

  • Example:

    Copy

      _sip._tcp.google.com.    SRV    10 60 5060 sipserver.google.com.
    

How DNS Records Work Together for google.com

When you type google.com in your browser:

  1. Your computer queries the DNS system for the A record or AAAA record of google.com.

  2. The DNS server responds with the IP address (e.g., 142.250.193.174 for IPv4 or 2404:6800:4007:821::200e for IPv6).

  3. Your browser connects to that IP address to load the website.

Similarly, when you send an email to @google.com, the DNS system uses the MX record to find the mail server responsible for handling emails for that domain.