A simple DNS server implementation for learning DNS internals.
- ✅ Authoritative DNS Server - Serves local domains from zone files
- ✅ Recursive DNS Resolver - Queries external DNS servers for unknown domains
- ✅ Complete DNS Record Support - All 8 record types (A, CNAME, NS, SOA, TXT, MX, PTR, SRV)
- ✅ Hybrid DNS Server - Both authoritative and recursive in one server
- ✅ Root Server Simulator - Simulates the 13 DNS root servers
- ✅ TLD Server Simulator - Simulates Top Level Domain servers (.com, .org, .net)
- ✅ Enhanced Recursive Resolver - Full DNS hierarchy simulation
- ✅ Complete DNS Hierarchy - Root → TLD → Authoritative flow
- ✅ Zone file loading (JSON format)
- ✅ UDP servers on multiple ports (8053-8057)
- ✅ Multiple record types per domain
- ✅ TTL support for all records
mini-dns/
├── server/
│ └── dns_server.py # Authoritative DNS server (port 8053)
├── recursive.py # Recursive DNS resolver (port 8054)
├── root_server.py # Root DNS server simulator (port 8055)
├── tld_server.py # TLD DNS server simulator (port 8056)
├── enhanced_recursive.py # Enhanced recursive resolver (port 8057)
├── test_dns_hierarchy.py # DNS hierarchy testing script
├── simple_hierarchy_demo.py # DNS hierarchy demonstration
├── zone/
│ ├── zones.json # Zone configuration
│ └── zone_loader.py # Zone file loader
└── README.md
-
Install dependencies
pip install dnslib
-
Run the servers
# Individual servers python3 server/dns_server.py # Authoritative DNS server (port 8053) python3 recursive.py # Recursive DNS resolver (port 8054) # DNS hierarchy simulation servers python3 root_server.py # Root DNS server (port 8055) python3 tld_server.py # TLD DNS server (port 8056) python3 enhanced_recursive.py # Enhanced recursive resolver (port 8057)
Alternatively, you can use vscode tasks to run the servers.
Steps:
- Open the repository in vscode.
- Click
Ctrl+Shift+Pto open the command palette. - Type
Tasks: Run Taskand pressEnter. - Select the task you want to run and press
Enter. (Use taskRun All Serversto run all servers at once) - The server(s) will start running in the terminal.
- Take all the terminals to a single window and arrange them however you like. (Optional)
Note: The tasks are configured in the
.vscode/tasks.jsonfile. -
Test with dig
# Authoritative Server (Port 8053) - Local domains only dig @127.0.0.1 -p 8053 myapp.local A dig @127.0.0.1 -p 8053 myapp.local NS dig @127.0.0.1 -p 8053 myapp.local MX dig @127.0.0.1 -p 8053 myapp.local SRV # Recursive Resolver (Port 8054) - Local + External domains dig @127.0.0.1 -p 8054 myapp.local A # Local domain dig @127.0.0.1 -p 8054 google.com A # External domain # Enhanced Recursive Resolver (Port 8057) - Full hierarchy simulation dig @127.0.0.1 -p 8057 google.com A # Simulated hierarchy resolution dig @127.0.0.1 -p 8057 github.com A # Uses root → TLD → auth flow
-
Test DNS hierarchy simulation
# Test the complete hierarchy python3 test_dns_hierarchy.py # See hierarchy demonstration python3 simple_hierarchy_demo.py
The server is configured with these records:
- A Record:
192.168.1.100(IP address) - NS Records:
ns1.myapp.local.,ns2.myapp.local.(name servers) - SOA Record: Zone authority info (serial, refresh, retry, expire, minimum)
- MX Records: Mail servers with priorities
- Priority 10:
mail.myapp.local. - Priority 20:
mail2.myapp.local.
- Priority 10:
- TXT Records: SPF and verification strings
v=spf1 include:_spf.google.com ~allgoogle-site-verification=abc123
www.myapp.local.→myapp.local.(CNAME)mail.myapp.local.→192.168.1.101(A record)mail2.myapp.local.→192.168.1.102(A record)ns1.myapp.local.→192.168.1.103(A record)ns2.myapp.local.→192.168.1.104(A record)
100.1.168.192.in-addr.arpa.→myapp.local.(PTR record)
| Record Type | Purpose | Example |
|---|---|---|
| A | IPv4 address | myapp.local. A 192.168.1.100 |
| CNAME | Canonical name (alias) | www.myapp.local. CNAME myapp.local. |
| NS | Name server | myapp.local. NS ns1.myapp.local. |
| SOA | Start of authority | Zone metadata (serial, refresh, etc.) |
| MX | Mail exchange | myapp.local. MX 10 mail.myapp.local. |
| TXT | Text record | myapp.local. TXT "v=spf1 include:_spf.google.com ~all" |
| PTR | Pointer (reverse DNS) | 100.1.168.192.in-addr.arpa. PTR myapp.local. |
- Serves only local domains from zone files
- Fast response for known domains
- No external queries
- Serves local domains (authoritative)
- Queries external DNS servers for unknown domains
- Hybrid functionality - best of both worlds
- Simulates the 13 DNS root servers
- Knows about TLD servers (.com, .org, .net, .edu, .gov)
- Returns delegation information for TLD queries
- Simulates Top Level Domain servers (.com, .org, .net)
- Knows about specific domains and their authoritative servers
- Returns delegation information for domain queries
- Complete DNS hierarchy simulation
- Queries Root → TLD → Authoritative in sequence
- Demonstrates full DNS resolution process
┌─────────────┐ ┌─────────────────┐ ┌──────────────┐ ┌──────────────┐
│ Client │───▶│ Enhanced │───▶│ Root │───▶│ TLD │
│ (dig) │ │ Recursive │ │ Server │ │ Server │
│ │ │ (Port 8057) │ │ (Port 8055) │ │ (Port 8056) │
└─────────────┘ └─────────────────┘ └──────────────┘ └──────────────┘
│ │ │
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Authoritative │ │ TLD Delegation │ │ Domain │
│ Server │ │ (.com, .org) │ │ Delegation │
│ (Port 8053) │ │ │ │ (google.com) │
└──────────────┘ └──────────────┘ └──────────────┘
Resolution Steps:
- Client queries Enhanced Recursive (8057) for google.com
- Enhanced Recursive queries Root Server (8055) for .com delegation
- Root Server responds with TLD server information
- Enhanced Recursive queries TLD Server (8056) for google.com delegation
- TLD Server responds with authoritative server information
- Enhanced Recursive queries authoritative servers for final answer
- Client receives the IP address
Following the DNS learning roadmap, this project has implemented:
- Add more record types (NS, SOA, TXT, MX, PTR, SRV)
- Implement recursive resolution
- Build root server simulator
- Build TLD server simulator
- Complete DNS hierarchy simulation
- Enhanced recursive resolver with full hierarchy traversal
- Testing framework for hierarchy validation
- Add caching system for performance optimization
- Implement DNSSEC (DNS Security Extensions)
- Add more realistic root server data
- Build DNS load balancing mechanisms
- Add comprehensive logging and monitoring
- Implement DNS over HTTPS (DoH)
- Add performance benchmarking tools