Domain Name System (DNS)

Learn the detailed workings of the domain name system and how domain names get translated to IP addresses through the DNS.

Let’s consider the example of a mobile phone where a unique number is associated with each user. To make calls to friends, we can initially try to memorize some of the phone numbers. However, as the number of contacts grows, we’ll have to use a phone book to keep track of all our contacts. This way, whenever we need to make a call, we’ll refer to the phone book and dial the number we need.

Similarly, computers are uniquely identified by IP addresses—for example, 104.18.2.119 is an IP address. We use IP addresses to visit a website hosted on a machine. Since humans cannot easily remember IP addresses to visit domain names (an example domain name being educative.io), we need a repository, similar to a phone book, that can maintain all the mappings of domain names to IP addresses. In this lesson, we’ll see how the DNS serves as the Internet’s phone book.

What is the DNS?

The domain name system (DNS) is the Internet’s naming service that maps human-friendly domain names to machine-readable IP addresses. The service of the DNS is transparent to users. When a user enters a domain name in the browser, the browser has to translate the domain name to an IP address by asking the DNS infrastructure. Once the desired IP address is obtained, the user’s request is forwarded to the destination web server.

The slides below show the high-level flow of how the DNS works:

The entire operation is performed very quickly. Therefore, the end user experiences minimum delay. We’ll also see how browsers save some of the frequently used mappings for later use in the next section.

Important details

Let’s highlight some of the important details about the DNS:

  • Name servers: It’s important to understand that the DNS isn’t a single server. It’s a complete infrastructure with numerous servers. DNS servers that respond to user queries are called name servers.

  • Resource records: The DNS database stores domain name to IP address mappings in the form of resource records (RRs). The RR is the smallest unit of information that users request from the name servers. There are different types of RRs. The table below describes common RRs. The three important pieces of information are type, name, and value. The name and value change depending upon the type of the RR.

Common Types of Resource Records

Type

Description

Name

Value

Example (Type, Name, Value)

A

Provides the hostname to IP address mapping

Hostname

IP address

(A, relay1.main.educative.io,104.18.2.119)

NS

Provides the hostname that is the authoritative DNS for a domain name

Domain name

Hostname

(NS, educative.io, dns.educative.io)

CNAME

Provides the mapping from an alias to the canonical hostname

Hostname

Canonical name

(CNAME, educative.io, server1.primary.educative.io)

MX

Provides the mapping of the mail server from the alias to the canonical hostname

Hostname

Canonical name

(MX, mail.educative.io, mailserver1.backup.educative.io)

  • Caching: The DNS uses caching at different layers to reduce request latency for the user. Caching plays an important role in reducing the burden on DNS infrastructure because it has to cater to the queries of the entire Internet.
  • Hierarchy: DNS name servers are in a hierarchical form. The hierarchical structure allows the DNS to be highly scalable because of its increasing size and query load. In the next section, we’ll look at how a tree-like structure is used to manage the entire DNS database.

DNS hierarchy

Through this section, we’ll answer the following questions:

  • How is the DNS hierarchy formed using various types of DNS name servers?
  • How is caching performed at different levels of the Internet to reduce the querying burden over the DNS infrastructure?
  • How does the distributed nature of the DNS infrastructure help its robustness?

As stated before, the DNS isn’t a single server that accepts requests and responds to user queries. It’s a complete infrastructure with name serversName servers can respond to users’ DNS queries. at different hierarchies.

There are four main types of servers in the DNS hierarchy:

  • DNS resolver: Resolvers initiate the querying sequence and forward requests to the other DNS name servers. Typically, DNS resolvers lie within the premise of the user’s network. However, DNS resolvers can also cater to users’ DNS queries through caching techniques, as we will see shortly. These servers can also be called local or default servers.
  • Root-level name servers: These servers receive requests from local servers. Root name servers maintain name servers based on top-level domain names, such as .com, .edu, .us, and so on. For instance, when a user requests the IP address of educative.io, root-level name servers will return a list of top-level domain (TLD) servers that hold the IP addresses of the .io domain.
  • Top-level domain (TLD) name servers: These servers hold the IP addresses of authoritative name servers. The querying party will get a list of IP addresses that belong to the authoritative servers of the organization.
  • Authoritative name servers: These are the organization’s DNS name servers that provide the IP addresses of the web or application servers.

Point to Ponder

Question

How are DNS names processed? For example, will educative.io be processed from left to right or right to left?

Show Answer

Iterative versus recursive query resolution

There are two ways to perform a DNS query:

  • Iterative: The local server requests the root, TLD, and the authoritative servers for the IP address.
  • Recursive: The end user requests the local server. The local server further requests the root DNS name servers. The root name servers forward the requests to other name servers.

In the following illustration, the DNS query resolution is iterative from the perspective of the local/ISP server, as shown on the left side:

Note: An iterative query is typically preferred to reduce query load on the DNS infrastructure.

Caching

Caching refers to the temporary storage of frequently requested resource records. A record is a data unit within the DNS database that shows a name-to-value binding. Caching reduces response time to the user and decreases network traffic. When we use caching at different hierarchies, it can reduce a lot of querying burden on the DNS infrastructure. Caching can be implemented in the browser, operating systems, local name server within the user’s network, or the ISP’s DNS resolvers.

The slideshow below demonstrates the power of caching in the DNS:

Note: Even if there is no cache available to resolve a user’s query and it’s imperative to visit the DNS infrastructure, caching can still be beneficial. The local server or ISP DNS resolver can cache the IP addresses of TLD servers or authoritative servers and avoid requesting the root-level server.

DNS as a distributed system

Although the DNS hierarchy facilitates the distributed Internet that we know today, it’s a distributed system itself. The distributed nature of DNS has the following advantages:

  • It avoids becoming a single point of failure (SPOF).
  • It achieves low query latency so users can get responses from nearby servers.
  • It gets a higher degree of flexibility during maintenance and updates or upgrades. For example, if one DNS server is down or overburdened, another DNS server can respond to user queries.

There are 13 logical root name servers (named letter “A” through “M”) with many instances spread throughout the globe. These servers are managed by 12 different organizations.

Let’s now go over how DNS is scalable, reliable, and consistent.

Highly scalable

Due to its hierarchical nature, the DNS is a highly scalable system. Roughly 1,000 replicated instances of 13 root-level servers are strategically spread throughout the world to handle user queries. The working labor is divided among TLD and root servers to handle a query and the authoritative servers that are managed by the organizations themselves to make the entire system work. As shown in the DNS hierarchy tree above, different services handle different portions of the tree that enable the scalability and manageability of the system.

Point to Ponder

Question

To maintain high availability, should the time-to-live (TTL) value be large or small?

Show Answer

Reliable

There are three main reasons that the DNS is a reliable system:

  • Caching: The caching is done in the browser, the operating system, and the local name server, and the ISP DNS resolvers also maintain a rich cache of frequently visited services. Even if some DNS servers are temporarily down, cached records can be served to make the DNS a reliable system.
  • Server replication: The DNS has replicated copies of each logical server spread systematically across the globe to entertain user requests at low latency. The redundant servers improve the reliability of the overall system.
  • Protocol: Although many clients use the DNS over unreliable user datagram protocol (UDP), UDP has its advantages. UDPUDP does not maintain a connection to send/receive application data. is much faster and therefore improves DNS performance. Furthermore, Internet service reliability has improved since its inception, so UDP is usually favored over TCP. A DNS resolver can resend the UDP request if it didn’t get a reply to a previous one. This request-response needs just one round trip, which provides a shorter delay as compared to TCP, which needs a three-way handshake before data exchange.

Point to Ponder

Question

What happens if a network is congested? Should the DNS continue using UDP?

Show Answer

Consistent

DNS uses various protocols to update and transfer information among replicated servers in a hierarchy. The DNS compromises on strong consistency to achieve high performance because data is read frequently from DNS databases as compared to writing. However, the DNS provides eventual consistency and lazily updates records on replicated servers. Typically, it can take from a few seconds up to three days to update records on the DNS servers across the Internet. The time it takes to propagate information among different DNS clusters depends on the DNS infrastructure, the size of the update, and the part of the DNS tree that is being updated.

Consistency can suffer because of caching too. Since authoritative servers are located within the organization, it may be possible that certain resource records are updated on the authoritative servers in case of server failures at the organization. Therefore, cached records at the default/local and ISP servers may be outdated. To mitigate this issue, each cached record comes with an expiration time called time to live (TTL)TTL refers to the period of time a record can be cached by the querying party. TTL values are reported in seconds..

Point to Ponder

Question

If we need the DNS to tell us which IP to reach a website or service, how will we know the DNS resolver’s IP address? (It seems like a chicken and egg problem.)

Show Answer