Skip to content

A high-performance DNS resolution server implementing RFC 1035 domain name compression technology, built with Rust and Tokio for production environments.

License

Notifications You must be signed in to change notification settings

WoWIllidan/dns-server-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DNS Server

CI Release Documentation Security Audit

A high-performance DNS server implementation in Rust with domain name compression support.

Features

  • RFC 1035 Compliant: Implements DNS protocol according to RFC 1035 specifications
  • Domain Name Compression: Full support for DNS message compression using pointer-based compression
  • Multiple Record Types: Supports A, AAAA, CNAME, MX, NS, and TXT record resolution with CNAME following
  • Configuration-Driven: TOML configuration file for easy server and record management
  • TTL Support: Configurable Time-To-Live values for all DNS records
  • Real-time Metrics: Query counters, response times, and error tracking with periodic reporting
  • Rate Limiting: Configurable per-client query rate limiting to prevent abuse
  • Graceful Shutdown: Proper signal handling for clean server shutdown
  • CLI Interface: Command-line options with help and version information
  • Async Processing: Built on Tokio for high-performance asynchronous UDP packet handling
  • Structured Logging: Comprehensive logging system with configurable log levels
  • Test Client: Includes a client binary for testing and validation

Architecture

Core Components

  • DNS Header (src/header.rs): RFC 1035 compliant header parsing and serialization
  • DNS Message (src/message.rs): Complete message parsing with compression support
  • DNS Server (src/server.rs): Async UDP server with multi-record type processing
  • DNS Resolver (src/resolver.rs): Record storage and resolution logic with CNAME following
  • Compression (src/compression.rs): Domain name compression using pointer-based algorithm

Binary Targets

  • dns-server: Main DNS server binary
  • client: Test client for DNS query validation

Usage

Configuration

Create or edit config.toml to customize server settings and DNS records:

[server]
bind_address = "127.0.0.1"
port = 8053
log_level = "info"
max_queries_per_minute = 60  # Rate limiting per client

[dns]
default_ttl = 300

# Add your DNS records here
[[records.a]]
name = "example.com"
ip = "93.184.216.34"
ttl = 300

Running the Server

# Show help
cargo run --bin dns-server -- --help

# Start with default configuration (config.toml)
cargo run --bin dns-server

# Start with verbose mode (shows full configuration)
cargo run --bin dns-server -- --verbose

# Start with custom configuration file
cargo run --bin dns-server -- --config /path/to/custom.toml

# Show version information
cargo run --bin dns-server -- --version

The server will:

  • Load configuration from specified file (default: config.toml)
  • Set log level from configuration
  • Bind to the configured address and port
  • Enable rate limiting per client
  • Display real-time metrics every 60 seconds
  • Handle graceful shutdown on SIGINT/SIGTERM

Testing with Client

# Send test DNS query for example.com
cargo run --bin client

Build Release Version

cargo build --release

Technical Implementation

Domain Name Compression

The server implements RFC 1035 Section 4.1.4 domain name compression:

  • Uses pointer-based compression with 2-byte pointers
  • Maintains compression offset mapping during response generation
  • Supports recursive pointer following during parsing
  • Reduces message size for responses with repeated domain names

Record Resolution

  • A Records: IPv4 address resolution with configurable TTL
  • AAAA Records: IPv6 address resolution with configurable TTL
  • CNAME Records: Canonical name resolution with automatic following
  • MX Records: Mail exchange records with priority support
  • NS Records: Name server delegation records
  • TXT Records: Text records for various purposes (SPF, DKIM, etc.)

Async Architecture

  • Built on Tokio async runtime
  • Non-blocking UDP socket processing
  • Concurrent request handling
  • Structured error handling and logging

Development Process

This project was developed using incremental commits mimicking real software development:

  1. Initial project structure and Git setup
  2. DNS header implementation with serialization
  3. UDP server framework with async processing
  4. DNS message parsing with basic functionality
  5. Multi-record type support (A, AAAA, CNAME)
  6. Domain name compression implementation
  7. Test client creation
  8. Logging system integration
  9. Code quality improvements

Each commit represents a functional milestone with descriptive English commit messages.

Dependencies

  • tokio: Async runtime with full feature support (networking, time, signals, sync)
  • serde: Serialization framework for configuration parsing
  • toml: TOML configuration file parsing
  • clap: Command-line argument parsing with help generation
  • log: Logging facade
  • env_logger: Environment-based logging configuration

License

This project is developed for educational and demonstration purposes.

About

A high-performance DNS resolution server implementing RFC 1035 domain name compression technology, built with Rust and Tokio for production environments.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages