A hierarchical DNS (Domain Name System) server simulation implemented in Java that demonstrates the DNS resolution process using a multi-tier architecture including Root DNS, TLD (Top-Level Domain) DNS, Authoritative DNS, and Local DNS servers.
This project simulates how the Domain Name System works in real-world networks. When a client queries a domain name, the request flows through multiple DNS servers in a hierarchical manner until the IP address is resolved.
The project implements a 4-tier DNS hierarchy:
- Local DNS Server - First point of contact for client queries
- Root DNS Server - Directs queries to appropriate TLD servers
- TLD DNS Server - Handles top-level domains (.com, .org, etc.)
- Authoritative DNS Server - Contains actual domain-to-IP mappings
- Hierarchical DNS Resolution - Simulates real-world DNS query flow
- Multi-threaded Client Support - Handles multiple concurrent client requests
- UDP Socket Communication - Uses datagram sockets for DNS queries
- DNS Record Types Support:
- A Records (IPv4 addresses)
- CNAME Records (Canonical names/aliases)
- Local DNS Caching - Stores resolved queries in local DNS table
- Custom DNS Tables - Configurable DNS records for each server tier
DNS/
├── src/
│ ├── client/
│ │ ├── Client.java # Main client application
│ │ └── ClientThread.java # Handles client requests in separate threads
│ └── server/
│ ├── Server.java # Abstract base class for all DNS servers
│ ├── LocalDNS.java # Local DNS server implementation
│ ├── rootDNS.java # Root DNS server implementation
│ ├── TLD_DNS.java # Top-Level Domain DNS server
│ └── AuthoritativeDNS.java # Authoritative DNS server
├── local_dns_table.txt # Local DNS cache/records
├── root_dns_table.txt # Root DNS server records
├── TLD_dns_table.txt # TLD server records
├── authoritative_dns_table.txt # Authoritative server records
└── build.xml # Ant build configuration
- Java Development Kit (JDK) 8 or higher
- Apache Ant (for building with build.xml) or any Java IDE
- Basic understanding of networking and DNS concepts
-
Clone the repository:
git clone https://github.com/hinaamin375/DNS-Java-Project.git cd DNS-Java-Project -
Compile the project:
Using Ant:
ant compile
Or manually:
javac -d build/classes src/client/*.java src/server/*.java
The DNS servers need to be started in the following order:
-
Start Authoritative DNS Server:
java -cp build/classes server.AuthoritativeDNS
-
Start TLD DNS Server:
java -cp build/classes server.TLD_DNS
-
Start Root DNS Server:
java -cp build/classes server.rootDNS
-
Start Local DNS Server:
java -cp build/classes server.LocalDNS
Once all servers are running, start the client:
java -cp build/classes client.ClientEnter domain names to resolve their IP addresses.
Each DNS table file follows this format:
domainname IPaddress [CNAME]
Example entries:
google.com 142.250.80.46
www.google.com 142.250.80.46 google.com
example.org 93.184.216.34
- Client sends a DNS query to the Local DNS Server
- Local DNS checks its cache/table
- If not found, forwards request to Root DNS Server
- Root DNS directs to appropriate TLD Server
- TLD Server directs to Authoritative DNS Server
- Authoritative DNS returns the IP address
- Response travels back through the hierarchy to the client
- Local DNS caches the result for future queries
- Network Programming - UDP socket communication in Java
- Multi-threading - Concurrent client request handling
- Design Patterns - Abstract classes and inheritance
- DNS Protocol - Understanding hierarchical DNS resolution
- Client-Server Architecture - Distributed system design
- Language: Java
- Network Protocol: UDP (User Datagram Protocol)
- Port Configuration: Custom ports for each DNS server tier
- Data Structure: File-based DNS record storage
- Concurrency: Thread-based client handling
- Understanding DNS hierarchy and resolution process
- Java socket programming with DatagramSocket and DatagramPacket
- Multi-threaded server implementation
- Network protocol design and implementation
- Object-oriented design with inheritance and abstraction
- Add DNS cache expiration (TTL implementation)
- Support for additional record types (MX, NS, AAAA)
- GUI interface for monitoring DNS queries
- Performance metrics and logging
- DNSSEC implementation for security
- Dynamic DNS record updates
- Database integration for DNS records
- REST API for DNS management
Port Already in Use:
- Make sure no other instances of the servers are running
- Check if ports are available using
netstatorlsof
Connection Timeout:
- Ensure all servers are started in the correct order
- Verify firewall settings allow UDP traffic
FileNotFoundException:
- Ensure all DNS table files exist in the project root
- Check file paths are correct relative to execution directory
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/Enhancement) - Commit your changes (
git commit -m 'Add some enhancement') - Push to the branch (
git push origin feature/Enhancement) - Open a Pull Request
This project is open source and available under the MIT License.
Your Name
- GitHub: @hinaamin375
- RFC 1034 & RFC 1035 - Domain Names Concepts and Facilities
- Java Network Programming documentation
- Computer Networks course materials
- Open-source DNS implementations for reference
⭐ If you found this project helpful, please give it a star! ⭐