Skip to main content

Command Palette

Search for a command to run...

Getting Started with DNS

Understanding the Basics of DNS

Published
•4 min read•View as Markdown
Getting Started with DNS
S

I’m a full stack developer documenting what I learn through writing and code.

DNS can be thought of as the internet's phone book, translating human-friendly domain names into numerical IP addresses. It's like when you want to call a friend; you don't need to remember their phone number, you just enter their name in your phone book to call them.

Similarly, with DNS, you don't need to remember all the IP addresses. You can simply type the domain name to access the website.

How DNS works

When you type a domain name into your browser, the browser first checks its local cache to see if it already knows the corresponding IP address. If the IP address is found, the request is resolved immediately.

If the IP address is not found locally, the browser sends the request to a recursive DNS resolver (usually provided by the ISP or a public DNS service).

If the recursive resolver does not have the answer cached, it begins a DNS lookup process:

  1. The resolver queries a root name server, asking which server is responsible for the .com TLD.
    The root server does not know the IP address but returns the TLD name servers.

  2. The resolver then queries the TLD server (for example, .com), asking which name servers are authoritative for xyz.com.
    The TLD server responds with the authoritative name servers for the domain.

  3. The resolver then queries the authoritative name server, which contains the actual DNS records.
    The authoritative server responds with the IP address of xyz.com.

The recursive resolver caches this response and returns the IP address to the client, allowing the browser to connect to the website.

Different record types in DNS

  1. A Record

    The A (Address) record is the fundamental DNS record. It maps a domain name to an IPv4 address.

    Example: example.com → 93.184.216.34

  2. AAAA Record

    The AAAA record works the same way as an A record, but it maps a domain name to an IPv6 address.

    Example: example.com → 2606:2800:220:1:248:1893:25c8:1946

  3. CNAME Record

    The CNAME (Canonical Name) record creates an alias for a domain name. Instead of pointing directly to an IP address, it points to another domain name.

    Example: student.example.com → CNAME → example.com

    When a client queries student.example.com

    1. DNS sees the CNAME record

    2. It resolves example.com

    3. It then returns the IP address from the A or AAAA record of example.com

This allows multiple domain names to point to the same destination without duplicating IP addresses.

  1. MX Record

    An MX (Mail Exchange) record directs incoming emails to the appropriate mail servers for a domain

    An MX record consists of two components:

    Priority – determines the order in which mail servers are tried

    Mail server hostname – the server responsible for receiving emails

The lower the priority number, the higher the priority.
When an email is sent, the sending mail server first attempts delivery to the mail server with the lowest priority value. If that server is unavailable, it then tries the next one in order.

test.comrecord typepriorityvalueTTL
@MX10mailhost1.test.com3600
@MX20mailhost2.test.com3600
  1. TXT Record

    TXT (Text) records are DNS records that allow domain owners to add arbitrary text data to their DNS configuration.

    These records are not visible on the website, but they play a crucial role behind the scenes. TXT records are commonly used for:

    • Domain ownership verification

    • Email authentication

    • Security policies

They are widely used by systems such as SPF, DKIM, and DMARC to verify that emails sent from a domain are legitimate.

  1. NS Record

    NS (Name Server) records specify which name servers are authoritative for a domain. They tell the internet where the DNS records for a domain are stored.

    NS records act like directories, pointing DNS resolvers to the name servers that contain the actual DNS records for the domain.

    When a DNS resolver needs information about a domain, it uses the NS records to know which servers to query for authoritative answers.