Unraveling the DNS Resolution Process: How Your Device Finds the Right IP
Overview of DNS resolution process
-
Start DNS Resolution Process
- The process begins with a Stub Resolver.
-
Local DNS Cache Check
- Stub Resolver checks the local DNS client cache.
- If there's a cache hit, the cached result is used.
- Stub Resolver checks the local DNS client cache.
-
Check Local Hosts File (Optional)
- Stub Resolver checks the
/etc/hosts
file.- If an entry is found, that result is used.
- Stub Resolver checks the
-
Use Specified DNS Server
- Stub Resolver uses the DNS server specified in
/etc/resolv.conf
.
- Stub Resolver uses the DNS server specified in
-
Send Query to Preferred DNS Server
- Stub Resolver sends a query to the preferred DNS server.
-
Query Other Configured DNS Servers (Optional)
- If the preferred DNS server does not return a result, other configured DNS servers are queried.
-
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.
-
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: