Sub topic 2
What Happens on Your Machine First
Assume you know basic IPv4 and IPv6 addresses, client-server communication, ports, and terminal commands. DNS resolution usually starts before any packet reaches a root server.
Local resolution
An application asks the operating system to resolve a host name, such as www.example.com. The operating system uses a stub resolver, a small client component that checks local sources and sends DNS queries to a configured recursive resolver.
The local process commonly checks these sources:
- A local hosts file, which contains manually defined name-to-address mappings.
- A local DNS cache.
- Search domains, which can turn a short name such as
printerintoprinter.office.example. - The configured recursive resolver, often supplied by a router, company network, internet provider, or public DNS service.
An application usually does not contact root or authoritative servers directly.
import socket
results = socket.getaddrinfo("example.com", 443, type=socket.SOCK_STREAM)
for family, socktype, proto, canonname, sockaddr in results:
print(family.name, sockaddr[0])Recursive resolvers
A recursive resolver performs the lookup for the stub resolver. It may already have a valid cached answer. Otherwise, it follows referrals through the DNS hierarchy and returns the final result to the client.
Following a lookup from root to answer
For www.example.com, the resolver can proceed as follows:
- The root server identifies the servers responsible for
.com. - A
.comserver identifies the authoritative servers forexample.com. - An authoritative server returns the record for
www.example.com. - The recursive resolver sends that answer back to the stub resolver.
A referral is not the final address. It tells the resolver where to ask next.
Caching and TTL
Each DNS record has a time to live (TTL) in seconds. A resolver can reuse a cached answer until its TTL reaches zero. Caching reduces latency and query traffic, but it means different resolvers can temporarily hold different answers after a record changes.
Use dig to inspect an answer and its remaining TTL:
dig +noall +answer example.com AThe number before IN is the remaining TTL, not the original value.
Exercise
Why might two recursive resolvers return different addresses for the same name?
Show answer
They may have cached different answers with different remaining TTLs, or one may have refreshed after a DNS change while the other has not.