Skip to main content

Unraveling the DNS Resolution Process: How Your Device Finds the Right IP

Overview of DNS resolution process

  1. Start DNS Resolution Process

    • The process begins with a Stub Resolver.
  2. Local DNS Cache Check

    • Stub Resolver checks the local DNS client cache.
      • If there's a cache hit, the cached result is used.
  3. Check Local Hosts File (Optional)

    • Stub Resolver checks the /etc/hosts file.
      • If an entry is found, that result is used.
  4. Use Specified DNS Server

    • Stub Resolver uses the DNS server specified in /etc/resolv.conf.
  5. Send Query to Preferred DNS Server

    • Stub Resolver sends a query to the preferred DNS server.
  6. Query Other Configured DNS Servers (Optional)

    • If the preferred DNS server does not return a result, other configured DNS servers are queried.
  7. Query Root DNS Server (If Necessary)

    • If no result is obtained from any configured DNS servers, the preferred DNS server queries the Root DNS Server.
  8. Receive Final IP Address

    • The Root DNS Server returns the result to the preferred DNS server, which then sends the final IP address to the Stub Resolver.

The optional steps indicate actions that may be skipped depending on whether previous steps have resolved the DNS query.

The Code

The above diagram is generated from the following code: