Mastering DNS: A Comprehensive Overview of Internet Address Translation
Several topics like this are discussed on my YouTube channel. Please visit. I appreciate your support.
The Domain Name System (DNS) serves as the internet’s directory, translating human-readable domain names into numerical IP addresses that computers use to identify each other on the network. It functions similarly to an address book in the digital world, providing a crucial service that simplifies internet navigation.
Imagine you want to visit a website, let’s say “www.example.com." Without DNS, you would need to remember the website’s numerical IP address, which might look something like “192.0.2.1.” However, human brains are better at remembering words than strings of numbers. DNS steps in to bridge this gap.
When you enter ‘www.example.com' into your web browser, the browser first checks its cache for the corresponding IP address. If not found, it then checks the operating system’s cache. The operating system facilitates communication between the browser and the DNS resolver. If the IP address is still not found, the browser sends a request to a DNS resolver, which acts as a virtual librarian. The DNS resolver searches its cache for the mapping of ‘www.example.com' to an IP address. If the information is not found in the resolver’s cache, it queries the DNS infrastructure for the IP address.
Once the IP address is located, it is returned to the browser via the operating system, allowing it to connect to the correct web server and retrieve the desired webpage.
A DNS resolver could be from your ISP or from DNS providers like Cloudflare’s 1.1.1.1 or Google’s 8.8.8.8.
Below is the pictorial representation of how DNS works.
When a DNS query for a website returns multiple IP addresses, the web browser leverages the results provided by the DNS resolver to choose an appropriate IP address.
Following the DNS resolution process, which identifies the IP addresses for a domain name, the web browser employs strategies like round-robin or caching to select an IP address for connecting to the website.
Components of DNS
In the Domain Name System (DNS), several key components work together to resolve domain names to IP addresses and vice versa. Here’s an explanation of each:
1. Name Servers: Name servers are specialized servers responsible for storing and providing DNS information. They maintain databases called zone files, which contain mappings of domain names to IP addresses and other DNS information. Name servers respond to DNS queries from clients by providing the requested information or referring the client to another name server if necessary.
2. Resource Records: Resource records (RRs) are the fundamental data elements stored in DNS zone files. Each domain has its own zone file, typically stored on the name servers responsible for that domain. Each resource record represents a piece of information associated with a domain name.
1. Caching: 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.
2. Hierarchy: DNS name servers are structured hierarchically. This allows for scalability and efficient query resolution.
In the DNS hierarchy, there are primarily four types of servers:
1. DNS Resolver: Resolvers initiate the querying sequence and forward requests to other DNS name servers. Typically located within the user’s network, these servers can also serve users’ DNS queries through caching techniques. These servers are also known as local or default servers.
2. Root-Level Name Servers: These servers handle requests from local servers and maintain name servers based on top-level domain names (TLDs) like .com, .edu, .us, etc. For example, if a user requests the IP address of example.com, root-level name servers will provide a list of TLD servers holding the IP addresses of the .com domain. There are 13 logical root name servers (named letters A through M) with many instances spread throughout the globe. These servers are managed by 12 different organizations. The 12 different organizations that manage the 13 logical root name servers are known as the Root Server Operators (RSOs). These organizations are responsible for operating and maintaining the infrastructure of the root name servers.
Some of the organizations involved include:
1. Top-Level Domain (TLD) Name Servers: These servers store the IP addresses of authoritative name servers. When queried, they return a list of IP addresses belonging to the authoritative servers of the organization.
2. Authoritative Name Servers: These DNS name servers belong to the organization and provide the IP addresses of web or application servers. They serve as the final authority for DNS resolution within the organization’s domain.
How are DNS names processed? For example, will example.com be processed from left to right or right to left? Can you guess?
DNS names are processed from right to left. In the case of example.com, the resolvers will first resolve the .com part, then example, and so on.
DNS Query Resolution
In DNS query resolution, there are two main methods: iterative and recursive.
Iterative Resolution: In iterative resolution, the DNS resolver sends a query to a root-level name server and awaits either the requested information or a referral to another top-level domain (TLD) name server that may have the information. If the queried TLD name server lacks the requested information, it returns a referral to a different name server. The resolver then sends a new query to this referred name server.
This process repeats until the resolver either receives the requested information or reaches the authoritative DNS server.
Recursive Resolution: In recursive resolution, the DNS resolver sends a query to a root name server and expects a comprehensive response containing the requested information. If the queried root name server lacks the information, it recursively queries other DNS servers, such as TLD and authoritative name servers, on behalf of the resolver until it obtains the requested information.
The DNS resolver’s configuration determines whether it performs iterative or recursive resolution.
Caching
DNS caching is the process of temporarily storing DNS query results to speed up subsequent requests for the same information.
Caching occurs at various levels, including:
1. Browser Caches: Web browsers often cache DNS records locally to reduce DNS lookup times for frequently visited websites. When a user visits a website, the browser may store DNS information in its cache to expedite future visits to the same site.
2. OS Caches: Operating systems can also cache DNS records to improve system performance. OS-level DNS caching stores DNS query results locally, reducing the need for repeated DNS lookups for frequently accessed domains across different applications and services running on the system.
3. Resolver Caches: Caches maintained by DNS resolvers (such as those provided by ISPs or DNS servers) to store recently resolved DNS queries.
4. Domain Name Server Caches: These caches are maintained by name servers at various levels to store recently accessed resource records for the domains they are authoritative for. Root name servers, top-level domain (TLD) name servers, and authoritative name servers all utilize caching to improve DNS resolution efficiency.
In essence, DNS serves as the internet’s address translation service, converting user-friendly domain names into machine-readable IP addresses. Without DNS, navigating the internet would be akin to finding your way in a foreign city without a map or street signs, significantly complicating online communication and accessibility.
Must Read for Continuous Learning
- Mastering System Design
- Head First Design Patterns
- Clean Code: A Handbook of Agile Software Craftsmanship
- Java Concurrency in Practice
- Java Performance: The Definitive Guide
- Designing Data-Intensive Applications
- Designing Distributed Systems
- Clean Architecture
- Kafka — The Definitive Guide
- Becoming An Effective Software Engineering Manager