A high-performance DNS server implementation in Rust with domain name compression support.
- 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
- 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
- dns-server: Main DNS server binary
- client: Test client for DNS query validation
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# 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 -- --versionThe 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
# Send test DNS query for example.com
cargo run --bin clientcargo build --releaseThe 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
- 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.)
- Built on Tokio async runtime
- Non-blocking UDP socket processing
- Concurrent request handling
- Structured error handling and logging
This project was developed using incremental commits mimicking real software development:
- Initial project structure and Git setup
- DNS header implementation with serialization
- UDP server framework with async processing
- DNS message parsing with basic functionality
- Multi-record type support (A, AAAA, CNAME)
- Domain name compression implementation
- Test client creation
- Logging system integration
- Code quality improvements
Each commit represents a functional milestone with descriptive English commit messages.
- 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
This project is developed for educational and demonstration purposes.