DEV Community

Cover image for DNS Explained: Navigating the Web's Address Book!
Pavankumar Hegde
Pavankumar Hegde

Posted on

DNS Explained: Navigating the Web's Address Book!

Table of Contents

  1. Introduction

  2. Understanding DNS

  3. DNS Record Types

  4. Advanced DNS Concepts


Introduction

Welcome to the world of Domain Name System (DNS), a fundamental component of the internet that translates human-friendly domain names into machine-readable IP addresses. In this guide, we'll delve into the intricacies of DNS, exploring its architecture, record types, and common issues.

The Domain Name System (DNS) is a vital component of the internet infrastructure, serving as a decentralized naming system. It plays a crucial role in translating human-friendly domain names into machine-readable IP addresses. DNS operates primarily over UDP (User Datagram Protocol) on port 53 for regular queries and TCP (Transmission Control Protocol) on the same port for more extensive data transfers, such as zone transfers.

Working at the application layer of the Internet Protocol suite, DNS follows a hierarchical structure that includes the root domain, top-level domains (TLDs), second-level domains, and subdomains. The resolution process begins when a user enters a domain name in a web browser, triggering a series of queries to DNS servers. These servers work in a hierarchical manner until the IP address associated with the domain is found.


Understanding DNS

What is DNS?

The Domain Name System (DNS) is the phonebook of the Internet. Humans access information online through domain names, like cisco.com or google.com. Web browsers interact through Internet Protocol (IP) addresses. DNS translates domain names to IP addresses so browsers can load Internet resources.

Each device connected to the Internet has a unique IP address which other machines use to find the device. DNS servers eliminate the need for humans to memorize IP addresses such as 192.168.1.1 (in IPv4), or more complex newer alphanumeric IP addresses such as 2400:cb00:2048:1::c629:d7a2 (in IPv6).

How DNS Works?

  • The process of DNS resolution involves converting a hostname (such as www.example.com) into a computer-friendly IP address (such as 192.168.1.1).
  • An IP address is given to each device on the Internet, and that address is necessary to find the appropriate Internet device - like a street address is used to find a particular home.
  • When a user wants to load a webpage, a translation must occur between what a user types into their web browser (example.com) and the machine-friendly address necessary to locate the example.com webpage.
  • In order to understand the process behind the DNS resolution, it’s important to learn about the different hardware components a DNS query must pass between.
  • For the web browser, the DNS lookup occurs "behind the scenes" and requires no interaction from the user’s computer apart from the initial request.

Image description


DNS Server Types

DNS recursor : The recursor can be thought of as a librarian who is asked to go find a particular book somewhere in a library. The DNS recursor is a server designed to receive queries from client machines through applications such as web browsers. Typically the recursor is then responsible for making additional requests in order to satisfy the client’s DNS query.

Root nameserver : The root server is the first step in translating (resolving) human readable host names into IP addresses. It can be thought of like an index in a library that points to different racks of books - typically it serves as a reference to other more specific locations.

TLD nameserver : The top level domain server (TLD) can be thought of as a specific rack of books in a library. This nameserver is the next step in the search for a specific IP address, and it hosts the last portion of a hostname (In example.com, the TLD server is “com”).

Authoritative nameserver : This final nameserver can be thought of as a dictionary on a rack of books, in which a specific name can be translated into its definition. The authoritative nameserver is the last stop in the nameserver query. If the authoritative name server has access to the requested record, it will return the IP address for the requested hostname back to the DNS Recursor (the librarian) that made the initial request.

Types of DNS Queries

3 types of DNS queries:

Recursive query - 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 query - in this situation the DNS client will allow a DNS server to return the best answer it can. If the queried DNS server does not have a match for the query name, it will return a referral to a DNS server authoritative for a lower level of the domain namespace. The DNS client will then make a query to the referral address. This process continues with additional DNS servers down the query chain until either an error or timeout occurs.

Non-recursive query - typically this will occur when a DNS resolver client queries a DNS server for a record that it has access to either because it's authoritative for the record or the record exists inside of its cache. Typically, a DNS server will cache DNS records to prevent additional bandwidth consumption and load on upstream servers.

DNS Lookup Steps

  1. A user types ‘example.com’ into a web browser and the query travels into the Internet and is received by a DNS recursive resolver.

  2. The resolver then queries a DNS root nameserver (.).

  3. The root server then responds to the resolver with the address of a Top Level Domain (TLD) DNS server (such as .com or .net), which stores the information for its domains. When searching for example.com, our request is pointed toward the .com 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 8 steps of the DNS lookup have returned the IP address for example.com, the browser is able to make the request for the web page:

  1. The browser makes an HTTP request to the IP address.

  2. The server at that IP returns the webpage to be rendered in the browser.


Image description


DNS caching

The purpose of caching is to temporarily stored data in a location that results in improvements in performance and reliability for data requests. DNS caching involves storing data closer to the requesting client so that the DNS query can be resolved earlier and additional queries further down the DNS lookup chain can be avoided, thereby improving load times and reducing bandwidth/CPU consumption. DNS data can be cached in a variety of locations, each of which will store DNS records for a set amount of time determined by a time-to-live (TTL).

Modern web browsers are designed by default to cache DNS records for a set amount of time. The purpose here is obvious; the closer the DNS caching occurs to the web browser, the fewer processing steps must be taken in order to check the cache and make the correct requests to an IP address. When a request is made for a DNS record, the browser cache is the first location checked for the requested record.

In Chrome, you can see the status of your DNS cache by going to chrome://net-internals/#dns.


DNS Record Types

Some most important types of DNS record

1. A record: The "A" stands for "address" and this is the most fundamental type of DNS record: it indicates the IP address of a given domain.

2. AAAA record: DNS AAAA records match a domain name to an IPv6 address. DNS AAAA records are exactly like DNS A records, except that they store a domain's IPv6 address instead of its IPv4 address.

3. CNAME record: A "canonical name" (CNAME) record points from an alias domain to a "canonical" domain. A CNAME record is used in lieu of an A record, when a domain or subdomain is an alias of another domain. All CNAME records must point to a domain, never to an IP address. Imagine a scavenger hunt where each clue points to another clue, and the final clue points to the treasure. A domain with a CNAME record is like a clue that can point you to another clue (another domain with a CNAME record) or to the treasure (a domain with an A record).

4. MX record: A DNS 'mail exchange' (MX) record directs email to a mail server. The MX record indicates how email messages should be routed in accordance with the Simple Mail Transfer Protocol (SMTP, the standard protocol for all email). Like CNAME records, an MX record must always point to another domain.

5. TXT record: The DNS ‘text’ (TXT) record lets a domain administrator enter text into the Domain Name System (DNS). The TXT record was originally intended as a place for human-readable notes. However, now it is also possible to put some machine-readable data into TXT records. One domain can have many TXT records.

6. NS record: NS stands for ‘nameserver,’ and the nameserver record indicates which DNS server is authoritative for that domain (i.e. which server contains the actual DNS records). Basically, NS records tell the Internet where to go to find out a domain's IP address. A domain often has multiple NS records which can indicate primary and secondary nameservers for that domain. Without properly configured NS records, users will be unable to load a website or application.

7. SOA record: The DNS ‘start of authority’ (SOA) record stores important information about a domain or zone such as the email address of the administrator, when the domain was last updated, and how long the server should wait between refreshes.

8. SRV record: The DNS "service" (SRV) record specifies a host and port for specific services such as voice over IP (VoIP), instant messaging, and so on. Most other DNS records only specify a server or an IP address, but SRV records include a port at that IP address as well. Some Internet protocols require the use of SRV records in order to function.

9. PTR record: The Domain Name System, or DNS, correlates domain names with IP addresses. A DNS pointer record (PTR for short) provides the domain name associated with an IP address. A DNS PTR record is exactly the opposite of the 'A' record, which provides the IP address associated with a domain name.

DNS PTR records are used in reverse DNS lookups. When a user attempts to reach a domain name in their browser, a DNS lookup occurs, matching the domain name to the IP address. A reverse DNS lookup is the opposite of this process: it is a query that starts with the IP address and looks up the domain name.

10. CAA record: This is the ‘certification authority authorization’ record, it allows domain owners state which certificate authorities can issue certificates for that domain. If no CAA record exists, then anyone can issue a certificate for the domain. These records are also inherited by subdomains.

11. DNSKEY record: The ‘DNS Key Record’ contains a public key used to verify Domain Name System Security Extension (DNSSEC) signatures.

12. CERT record: The ‘certificate record’ stores public key certificates.

13. DCHID record: The ‘DHCP Identifier’ stores info for the Dynamic Host Configuration Protocol (DHCP), a standardized network protocol used on IP networks.

14. DMARC record: Domain-based Message Authentication Reporting and Conformance (DMARC) is a method of authenticating email messages. A DMARC policy tells a receiving email server what to do after checking a domain's Sender Policy Framework (SPF) and DomainKeys Identified Mail (DKIM) records, which are additional email authentication methods.

DMARC and other email authentication methods are necessary in order to prevent email spoofing. Every email address has a domain, which is the portion of the address that comes after the "@" symbol. Malicious parties and spammers sometimes try to send emails from a domain that they are not authorized to use — like someone writing the wrong return address on a letter. They may do this to try to trick users (as in a phishing attack), among other reasons.

15. DKIM record: DomainKeys Identified Mail (DKIM) is a method of email authentication that helps prevent spammers and other malicious parties from impersonating a legitimate domain.

All email addresses have a domain — the part of the address after the "@" symbol. Spammers and attackers may try to impersonate a domain when sending emails to carry out phishing attacks or other scams.

16. SPF record: A sender policy framework (SPF) record is a type of DNS TXT record that lists all the servers authorized to send emails from a particular domain. A DNS TXT (“text”) record lets a domain administrator enter arbitrary text into the Domain Name System (DNS). TXT records were initially created for the purpose of including important notices regarding the domain, but have since evolved to serve other purposes.

Advanced DNS Concepts

DNS Zone:

The DNS is broken up into many different zones. These zones differentiate between distinctly managed areas in the DNS namespace. A DNS zone is a portion of the DNS namespace that is managed by a specific organization or administrator. A DNS zone is an administrative space which allows for more granular control of DNS components, such as authoritative nameservers. The domain name space is a hierarchical tree, with the DNS root domain at the top. A DNS zone starts at a domain within the tree and can also extend down into subdomains so that multiple subdomains can be managed by one entity.

A common mistake is to associate a DNS zone with a domain name or a single DNS server. In fact, a DNS zone can contain multiple subdomains and multiple zones can exist on the same server. DNS zones are not necessarily physically separated from one another, zones are strictly used for delegating control.

For example, imagine a hypothetical zone for the cloudflare.com domain and three of its subdomains: support.cloudflare.com, community.cloudflare.com, and blog.cloudflare.com. Suppose the blog is a robust, independent site that needs separate administration, but the support and community pages are more closely associated with cloudflare.com and can be managed in the same zone as the primary domain. In this case, cloudflare.com as well as the support and community sites would all be in one zone, while blog.cloudflare.com would exist in its own zone.

DNS zones are basically administrative units that divide the domain name space in the Domain Name System (DNS). They help in managing and delegating domain names within a specific portion of the overall domain. There are different types of DNS zones, such as:


1. Primary Zone: This is the original read/write copy of the zone, and it is the authoritative source for the zone's information.

2. Secondary Zone: This is a read-only copy of the primary zone. It is used for backup and fault tolerance. If the primary DNS server fails, the secondary server can still provide domain information.

3. Stub Zone: This type of zone contains only a subset of the entire DNS namespace. It is used to resolve names between separate DNS namespaces.

4. Forward Lookup Zone: This zone is used to resolve domain names to IP addresses. It is the most common type of zone.

5. Reverse Lookup Zone: This zone is used to resolve IP addresses to domain names.

Each of these zones plays a specific role in the DNS hierarchy and helps ensure efficient and reliable domain name resolution.


Anycast DNS:

In Anycast, one IP address can apply to many servers. Anycast DNS means that any one of a number of DNS servers can respond to DNS queries, and typically the one that is geographically closest will provide the response. This reduces latency, improves uptime for the DNS resolving service, and provides protection against DNS flood DDoS attacks.

Typically, any device or server that connects directly to the Internet will have a unique IP address. Communication between network-connected devices is 1-to-1; each communication goes from one specific device to the targeted device on the other end of the communication. Anycast networks, in contrast, allow multiple servers on the network to use the same IP address, or set of IP addresses. Communication with an Anycast network is 1-to-many.

Ordinarily, an IP address functions like a street address: it specifies the one specific location where the message is going. But suppose a friend had multiple residences around the country. Imagine a letter addressed to one of her houses could go to any one of those other houses based on which one was closest to the sender, even though the letter was addressed to a house in another city. This is sort of how Anycast routing works: one IP address can be associated with multiple locations.

Recursive DNS:

A recursive DNS lookup is where one DNS server communicates with several other DNS servers to hunt down an IP address and return it to the client. This is in contrast to an iterative DNS query, where the client communicates directly with each DNS server involved in the lookup. While this is a very technical definition, a closer look at the DNS system and the difference between recursion and iteration should help clear things up.

Primary vs. secondary DNS:

What is a primary DNS server?

DNS, or the Domain Name System, translates domain names into IP addresses so users can easily navigate to sites on the Internet without having to memorize long, specific strings of numbers and letters.

In this system, a primary DNS server is a server that hosts a website’s primary zone file. This is a text database file that contains all of the authoritative information for a domain, including its IP address, the identity of the domain administrator, and various resource records. Resource records list domain names alongside their corresponding IP addresses, and can take several different forms:

  • A record: Directs a domain to an IPv4 address
  • AAAA record: Directs a domain to an IPv6 address
  • MX record: Assigns a mail server to a domain
  • NS record: Identifies authoritative DNS servers for a domain

Primary servers are also responsible for making any necessary changes to a zone’s DNS records. Once the primary server has completed the update, it can then pass along change requests to the secondary servers.

What is a secondary DNS server?

Primary DNS servers contain all relevant resource records and handle DNS queries for a domain. By contrast, secondary DNS servers contain zone file copies that are read-only, meaning they cannot be modified. Instead of getting their information from local files, they receive pertinent information from a primary server in a communication process known as a zone transfer.

Zone transfers become more complicated when they are completed between multiple secondary servers. If several secondary servers are in use, one may be designated as a higher-tier secondary server so that it is capable of replicating zone file copies to the remaining pool of secondary servers.

Reverse DNS:

A reverse DNS lookup is a DNS query for the domain name associated with a given IP address. This accomplishes the opposite of the more commonly used forward DNS lookup, in which the DNS system is queried to return an IP address.

Standards from the Internet Engineering Task Force (IETF) suggest that every domain should be capable of reverse DNS lookup, but as reverse lookups are not critical to the normal function of the Internet, they are not a hard requirement. As such, reverse DNS lookups are not universally adopted.

Conclusion

we've delved into the intricate world of DNS, uncovering its pivotal role as the internet's address book. From the hierarchical structure guiding our online navigation to the seamless translation of user-friendly domain names into machine-readable IP addresses, DNS stands as a silent yet indispensable force shaping our digital experiences.

As we explored the protocol's reliance on both UDP and TCP, with the familiar port 53 orchestrating the flow of data, it became evident that DNS is more than a mere naming system; it's a dynamic network facilitator. Its caching mechanisms enhance efficiency, and the use of resource records provides a nuanced understanding of domain configurations.

In the ever-evolving landscape of the internet, grasping the fundamentals of DNS is akin to possessing a map in an uncharted territory. Our journey has unraveled the complexities, empowering us to navigate with a newfound appreciation for the invisible threads weaving the web together. Whether optimizing DNS performance or addressing security concerns, the significance of this protocol echoes in every click, reaffirming its status as an indispensable cornerstone of our online existence.

Congratulations! You've now gained a comprehensive understanding of DNS and its role in making the internet accessible.Feel free to ask questions or share your experiences in the comments below.

Contact Me

Feel free to reach out for collaborations, questions, or just to say hello!

References

  1. https://www.techtarget.com/searchnetworking/definition/domain-name-system

  2. https://www.hostinger.in/tutorials/what-is-dns

Top comments (0)