Post

Domain Name System (DNS)

Domain Name System (DNS)

We know about IP addresses that enable every machine to connect with other machines. But as we know humans are more comfortable with names than numbers. It’s easier to remember a name like google.com than something like 122.250.192.232.

This brings us to Domain Name System (DNS) which is a hierarchical and decentralized naming system used for translating human-readable domain names to IP addresses.

How DNS works

When we aim to reach example.com from our browser, we act as the user, and the server holds the desired information.

DNS lookup entails eight steps, orchestrated through interactions among four distinct components:

Components:

  1. DNS Resolver: A DNS resolver (also known as a DNS recursive resolver) is the first stop in a DNS query. The recursive resolver acts as a middleman between a client and a DNS nameserver. After receiving a DNS query from a web client, a recursive resolver will either respond with cached data, or send a request to a root nameserver, followed by another request to a TLD nameserver, and then one last request to an authoritative nameserver. After receiving a response from the authoritative nameserver containing the requested IP address, the recursive resolver then sends a response to the client.

  2. DNS Root Name Server: A root server accepts a recursive resolver’s query which includes a domain name, and the root nameserver responds by directing the recursive resolver to a TLD nameserver, based on the extension of that domain (.com, .net, .org, etc.). The root nameservers are overseen by a nonprofit called the Internet Corporation for Assigned Names and Numbers (ICANN).

    There are 13 DNS root nameservers known to every recursive resolver. Note that while there are 13 root nameservers, that doesn’t mean that there are only 13 machines in the root nameserver system. There are 13 types of root nameservers, but there are multiple copies of each one all over the world, which use Anycast routing to provide speedy responses.

  3. TLD (Top Level Domain) Name Server: A TLD nameserver maintains information for all the domain names that share a common domain extension, such as .com, .net, or whatever comes after the last dot in a URL.

    Management of TLD nameservers is handled by the Internet Assigned Numbers Authority (IANA), which is a branch of ICANN. The IANA breaks up the TLD servers into two main groups:

    • Generic top-level domains: These are domains like .com, .org, .net, .edu, and .gov.
    • Country code top-level domains: These include any domains that are specific to a country or state. Examples include .uk, .us, .ru, and .jp.
  4. Authoritative Name Server: The authoritative nameserver is usually the resolver’s last step in the journey for an IP address. The authoritative nameserver contains information specific to the domain name it serves (e.g. google.com) and it can provide a recursive resolver with the IP address of that server found in the DNS A record, or if the domain has a CNAME record (alias) it will provide the recursive resolver with an alias domain, at which point the recursive resolver will have to perform a whole new DNS lookup to procure a record from an authoritative nameserver (often an A record containing an IP address). If it cannot find the domain, returns the NXDOMAIN message.

DNS Workflow

Workflows…

DNS lookup involves the following eight steps:

  1. A client types example.com into a web browser, the query travels to the internet and is received by a DNS resolver.
  2. The resolver then recursively queries a DNS root nameserver.
  3. The root server responds to the resolver with the address of a Top-Level Domain (TLD).
  4. The resolver then makes a request to the .com TLD.
  5. The TLD server then responds with the IP address of the domain’s nameserver, example.com.
  6. Lastly, the recursive resolver sends a query to the domain’s nameserver.
  7. The IP address for example.com is then returned to the resolver from the nameserver.
  8. The DNS resolver then responds to the web browser with the IP address of the domain requested initially.

Once the IP address has been resolved, the client should be able to request content from the resolved IP address. For example, the resolved IP may return a webpage to be rendered in the browser.

Query Types

There are three types of queries in a DNS system:

Recursive

In a recursive query, a DNS client requires that a DNS server (typically a DNS recursive resolver) will respond to the client with either the requested resource record or an error message if the resolver can’t find the record.

Iterative

In an iterative query, a DNS client provides a hostname, and the DNS Resolver returns the best answer it can. If the DNS resolver has the relevant DNS records in its cache, it returns them. If not, it refers the DNS client to the Root Server or another Authoritative Name Server that is nearest to the required DNS zone. The DNS client must then repeat the query directly against the DNS server it was referred.

Non-recursive

A non-recursive query is a query in which the DNS Resolver already knows the answer. It either immediately returns a DNS record because it already stores it in a local cache, or queries a DNS Name Server which is authoritative for the record, meaning it definitely holds the correct IP for that hostname. In both cases, there is no need for additional rounds of queries (like in recursive or iterative queries). Rather, a response is immediately returned to the client.

Record Types

DNS records (aka zone files) are instructions that live in authoritative DNS servers and provide information about a domain including what IP address is associated with that domain and how to handle requests for that domain.

These records consist of a series of text files written in what is known as DNS syntax. DNS syntax is just a string of characters used as commands that tell the DNS server what to do. All DNS records also have a “TTL”, which stands for time-to-live, and indicates how often a DNS server will refresh that record.

There are more record types but for now, let’s look at some of the most commonly used ones:

  • A (Address record): This is the record that holds the IP address of a domain.
  • AAAA (IP Version 6 Address record): The record that contains the IPv6 address for a domain (as opposed to A records, which stores the IPv4 address).
  • CNAME (Canonical Name record): Forwards one domain or subdomain to another domain, does NOT provide an IP address.
  • MX (Mail exchanger record): Directs mail to an email server.
  • TXT (Text Record): This record lets an admin store text notes in the record. These records are often used for email security.
  • NS (Name Server records): Stores the name server for a DNS entry.
  • SOA (Start of Authority): Stores admin information about a domain.
  • SRV (Service Location record): Specifies a port for specific services.
  • PTR (Reverse-lookup Pointer record): Provides a domain name in reverse lookups.
  • CERT (Certificate record): Stores public key certificates.

Subdomains

A subdomain is an additional part of our main domain name. It is commonly used to logically separate a website into sections. We can create multiple subdomains or child domains on the main domain.

For example, blog.example.com where blog is the subdomain, example is the primary domain and .com is the top-level domain (TLD). Similar examples can be support.example.com or careers.example.com.

These are some widely used managed DNS solutions:

  • Route53
  • Cloudflare DNS
  • Google Cloud DNS
  • Azure DNS
  • NS1
This post is licensed under CC BY 4.0 by the author.