DEV Community

Aarshdeep Singh Chadha
Aarshdeep Singh Chadha

Posted on

1

From www.google.com to 172.217.5.253: The Magic of DNS

Image description

1. Introduction to DNS

  • Purpose of DNS: DNS (Domain Name System) translates human-readable domain names (e.g., www.google.com) into IP addresses (e.g., 172.217.5.253) that computers use to communicate over the internet.
  • Role of DNS in Browser Requests: When you type www.google.com in your browser, the browser doesn't directly use the domain name to establish a TCP connection. Instead, it uses the IP address associated with that domain name.

2. DNS Records and Zones

  • DNS Records: These are key-value pairs that map domain names to IP addresses or other resources.
    • A Record: Maps a domain name to an IPv4 address (e.g., www.google.com -> 172.217.5.253).
    • CNAME Record: Maps a domain name to another domain name (e.g., www.google.com -> cname.google.com).
    • MX Record: Specifies mail servers responsible for accepting email messages on behalf of a domain.
    • TXT Record: Used for text data, often for SPF, DKIM, etc.
  • DNS Zone: A DNS zone contains the DNS records for a specific domain (e.g., google.com). It is managed by an authoritative name server.
  • Hosted Zone: In services like AWS Route 53, a hosted zone is a collection of DNS records for a specific domain.

3. Authoritative Name Servers

  • Role: Authoritative name servers are responsible for storing and providing DNS records for a specific zone.
  • Example: If ns1.google.com is an authoritative name server for google.com, it will provide the IP address for www.google.com when queried.
  • Multiple Name Servers: Domains typically have multiple authoritative name servers for redundancy and fault tolerance.

4. DNS Resolvers

  • Role: DNS resolvers are responsible for initiating and managing the DNS query process on behalf of the client (e.g., your browser).
  • Location: DNS resolvers can be located at the ISP level, on your router, or even on your local machine.
  • Popular Public DNS Resolvers:
    • Google DNS: 8.8.8.8 and 8.8.4.4
    • Cloudflare DNS: 1.1.1.1
  • Caching: DNS resolvers cache DNS records to improve resolution speed and reduce load on authoritative name servers.

Image description

5. DNS Resolution Process

  • Step-by-Step Resolution:
    1. Client Request: Your browser sends a DNS query to the DNS resolver (e.g., your router).
    2. DNS Resolver Checks Cache: If the IP address for www.google.com is cached, it returns it immediately.
    3. Root Name Servers: If not cached, the resolver queries one of the 13 root name servers (e.g., a.root-servers.net).
      • Anycast: Root name servers use anycast to distribute queries across multiple physical servers with the same IP address.
    4. TLD Name Servers: The root name server responds with the IP address of a TLD (Top-Level Domain) name server for .com.
    5. Authoritative Name Servers: The TLD name server responds with the IP address of an authoritative name server for google.com.
    6. DNS Record Retrieval: The authoritative name server for google.com provides the IP address for www.google.com.
    7. Resolver Caches and Returns IP: The resolver caches the IP address and returns it to the client.
    8. TCP Connection Establishment: The browser uses the IP address to establish a TCP connection with the server.

6. Hierarchical Structure of DNS

  • Root Name Servers: 13 logically defined root name servers that form the root of the DNS hierarchy.
  • TLD Name Servers: Handle domains within a specific TLD (e.g., .com, .org, .net).
  • Authoritative Name Servers: Handle domains within a specific zone (e.g., google.com).

7. Anycast in DNS

  • Definition: Anycast is a networking technique where a single IP address is shared among multiple servers in different locations.
  • Benefits:
    • Load Distribution: Queries are distributed to the nearest server.
    • Fault Tolerance: If one server fails, queries are routed to another server with the same IP address.

8. Caching in DNS

  • Resolver Caching: DNS resolvers cache DNS records for a certain period (TTL - Time to Live).
  • Client Caching: Clients (e.g., browsers) also cache DNS records to reduce the number of DNS queries.
  • TTL: The time a DNS record is cached before it needs to be refreshed.

Image description

9. Example DNS Resolution

  • Scenario: Resolving www.google.com to an IP address.
  • Process:
    1. Client Query: Browser requests www.google.com.
    2. Resolver Query: Resolver queries root name server.
    3. Root Name Server Response: Points to .com TLD name server.
    4. TLD Name Server Response: Points to ns1.google.com (authoritative name server for google.com).
    5. Authoritative Name Server Response: Provides IP address for www.google.com.
    6. Resolver Caches IP: Resolver caches the IP address and returns it to the client.
    7. TCP Connection: Browser connects to the IP address.

Conclusion

The DNS resolution process is a critical component of the internet, enabling human-readable domain names to be translated into machine-readable IP addresses. Understanding the roles of DNS resolvers, authoritative name servers, and the hierarchical structure of DNS is essential for managing and troubleshooting DNS-related issues. The use of anycast and caching mechanisms ensures that DNS resolution is both efficient and scalable.

for more resources :

Image of Datadog

Measure and Advance Your DevSecOps Maturity

In this white paper, we lay out a DevSecOps maturity model based on our experience helping thousands of organizations advance their DevSecOps practices. Learn the key competencies and practices across four distinct levels of maturity.

Get The White Paper

Top comments (0)