A DNS resolver implementation in Rust, inspired by the classic dig command-line tool. This project provides a simple yet functional DNS client that can query domain names and resolve them to IP addresses.
- DNS Resolution: Query domain names and resolve them to IPv4 addresses
- System Integration: Automatically reads nameserver configuration from
/etc/resolv.conf - UDP Communication: Uses UDP sockets for efficient DNS queries
- Structured Logging: Built-in logging support with
env_logger - Binary Protocol: Implements DNS packet parsing and generation
- Command-line Interface: Simple CLI powered by
clap
git clone <repository-url>
cd dig-rs
cargo build --releaseThe binary will be available at target/release/dig-rs.
# Query a domain name
dig-rs example.com
# Query with debug logging
RUST_LOG=trace dig-rs example.comDomain exists at: 93.184.216.34
- Configuration: Reads the system's nameserver configuration from
/etc/resolv.conf - DNS Query: Constructs a DNS query packet for the specified domain
- Network Communication: Sends the query via UDP to the nameserver
- Response Parsing: Parses the DNS response and extracts IP addresses
- Output: Displays all resolved IP addresses
src/main.rs- Entry point and main application logicsrc/args.rs- Command-line argument parsing and nameserver configurationsrc/client.rs- DNS client implementation and network communicationsrc/packet/- DNS packet structures and serialization/deserialization
- anyhow - Error handling
- binrw - Binary reading/writing
- clap - Command-line argument parsing
- env_logger - Logging functionality
- log - Logging facade
- modular-bitfield - Bitfield operations for packet structures
- rand - Random number generation for DNS transaction IDs
cargo buildcargo testEnable trace logging to see detailed DNS communication:
RUST_LOG=trace cargo run -- example.com- Edition: Rust 2024
- Safety: Unsafe code is forbidden (
#[forbid(unsafe_code)]) - Protocol: Implements DNS over UDP (RFC 1035)
- Query Type: Currently supports A record queries (IPv4 addresses)
This project is open source. Please check the license file for more details.
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.