Skip to content

A hierarchical DNS server simulation in Java demonstrating the complete DNS resolution process with Root, TLD, and Authoritative servers. Features multi-threaded architecture, UDP communication, and comprehensive DNS record management.

Notifications You must be signed in to change notification settings

hinaamin375/DNS-Java-Project

Repository files navigation

DNS Server Simulation - Java Project

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.

📋 Project Overview

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.

🏗️ Architecture

The project implements a 4-tier DNS hierarchy:

  1. Local DNS Server - First point of contact for client queries
  2. Root DNS Server - Directs queries to appropriate TLD servers
  3. TLD DNS Server - Handles top-level domains (.com, .org, etc.)
  4. Authoritative DNS Server - Contains actual domain-to-IP mappings

🚀 Features

  • 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

📁 Project Structure

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

🛠️ Prerequisites

  • 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

📥 Installation & Setup

  1. Clone the repository:

    git clone https://github.com/hinaamin375/DNS-Java-Project.git
    cd DNS-Java-Project
  2. Compile the project:

    Using Ant:

    ant compile

    Or manually:

    javac -d build/classes src/client/*.java src/server/*.java

💻 Usage

Starting the DNS Servers

The DNS servers need to be started in the following order:

  1. Start Authoritative DNS Server:

    java -cp build/classes server.AuthoritativeDNS
  2. Start TLD DNS Server:

    java -cp build/classes server.TLD_DNS
  3. Start Root DNS Server:

    java -cp build/classes server.rootDNS
  4. Start Local DNS Server:

    java -cp build/classes server.LocalDNS

Running the Client

Once all servers are running, start the client:

java -cp build/classes client.Client

Enter domain names to resolve their IP addresses.

📝 DNS Table Format

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

🔍 How It Works

  1. Client sends a DNS query to the Local DNS Server
  2. Local DNS checks its cache/table
  3. If not found, forwards request to Root DNS Server
  4. Root DNS directs to appropriate TLD Server
  5. TLD Server directs to Authoritative DNS Server
  6. Authoritative DNS returns the IP address
  7. Response travels back through the hierarchy to the client
  8. Local DNS caches the result for future queries

🎓 Concepts Demonstrated

  • 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

🔧 Technical Implementation

  • 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

📚 Learning Outcomes

  • 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

🚧 Future Enhancements

  • 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

🐛 Troubleshooting

Port Already in Use:

  • Make sure no other instances of the servers are running
  • Check if ports are available using netstat or lsof

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

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/Enhancement)
  3. Commit your changes (git commit -m 'Add some enhancement')
  4. Push to the branch (git push origin feature/Enhancement)
  5. Open a Pull Request

📄 License

This project is open source and available under the MIT License.

👤 Author

Your Name

🙏 Acknowledgments

  • 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!

About

A hierarchical DNS server simulation in Java demonstrating the complete DNS resolution process with Root, TLD, and Authoritative servers. Features multi-threaded architecture, UDP communication, and comprehensive DNS record management.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages