This project implements a DNS resolver that performs iterative queries from root servers down to authoritative name servers to resolve domain names to IP addresses.
- Reads root server hints from
root.hints - Contacts root, TLD, and authoritative DNS servers via UDP
- Constructs and parses DNS query and response packets manually
- Supports DNS query types A (IPv4 address) and NS (Name Server)
- Caches DNS records locally with TTL support
- Handles additional and authority DNS sections including glue records
- Uses threading for concurrent query handling and periodic cache purging
- Implements EDNS(0) OPT pseudo-record for extended DNS features
See detailed explanation and design in Note.md.
-
Initialization
Loads root server IPs fromroot.hintsfile. -
Finding Nearest Root Server
Measures latency to root servers and selects the fastest for queries. -
DNS Query Construction
Builds DNS query packets including headers, questions, and optional EDNS record.+---------------------+ | Header | +---------------------+ | Question | +---------------------+ | Answer | +---------------------+ | Authority | +---------------------+ | Additional | +---------------------+ -
Iterative Resolution
- Query root server for TLD servers for the domain.
- Query TLD servers for it returns namerserver domain + glued ip (only if in same zone) like .com tld only will give hostinger.com nameserver ip not hostinger.net ip.
- Query authoritative servers for the final IP address.
root server --> tld server --> nameservernote:- sometimes tld only return nameserver domain name (because of out-zone) .so we have to start new query from starting for finding namerserver ip
root server --> tld server -->(gluedip) -
Response Parsing
Parses DNS response sections: answers, authority, and additional records.rootserver server returns:- only authority tld server server returns :- authority + additional nameserver returns :- answer
-
Caching
Stores resolved DNS records with TTL and purges expired entries periodically. we usedlmdbincache memory for fast reponse -
UDP Server
Listens locally on UDP port 1234 for incoming DNS queries and responds using cache or fresh resolution.
- Run the resolver: it listens on
127.0.0.1:1234UDP for DNS queries. - Queries are resolved by iterative DNS lookup and answered with cached or fresh data.
- Logs resolution steps and latency for debugging.
- Python 3.x
cache.pymodule for DNS record caching and management
- Supports only basic DNS query types (A and NS).
- No DNSSEC or advanced security features.
- Assumes IPv4-only queries and responses.
- Timeout handling with retries is basic.
- Support for other query types (AAAA, MX, TXT).
- Full DNSSEC validation.
- Better error handling and retry logic.
- IPv6 support.
- Performance optimizations and asynchronous IO.
This project demonstrates low-level DNS protocol handling and iterative resolver mechanics suitable for learning network programming and DNS internals.