A simple and fast DNS query tool written in pure Rust with no unsafe code.
- π Query various DNS record types: A, AAAA, NS, CNAME, MX
- π Detailed output: Shows complete DNS response information
- π Custom DNS servers: Query any DNS server
- β Thoroughly tested: Comprehensive unit test coverage
-
Make sure you have Rust installed. If not, install it from rustup.rs
-
Clone this repository:
git clone https://github.com/yaslam-dev/dns-rust.git cd dns-rust -
Build and install:
cargo build --release cargo install --path .OR
-
Install and Run
cargo test && cargo run -- cloudflare.com Acargo install dns-rustQuery an A record for a domain:
dns-rust google.com AQuery different record types:
dns-rust example.com MX
dns-rust github.com AAAA
dns-rust google.com NS
dns-rust www.github.com CNAMEUse a different DNS server (default is 8.8.8.8):
dns-rust google.com A --server 1.1.1.1
dns-rust example.com MX -s 9.9.9.9dns-rust [OPTIONS] <DOMAIN> <RECORD_TYPE>
Arguments:
<DOMAIN> The domain name to query
<RECORD_TYPE> The record type to query (A, AAAA, NS, CNAME, MX)
Options:
-s, --server <SERVER> DNS server to query (default: 8.8.8.8)
-h, --help Print help
-V, --version Print version
| Type | Description |
|---|---|
| A | IPv4 address records |
| AAAA | IPv6 address records |
| NS | Name server records |
| CNAME | Canonical name records |
| MX | Mail exchange records |
$ dns-rust google.com A
Querying 8.8.8.8:53 for A record of google.com
DNS Response:
=============
ID: 6666
Response: true
Authoritative: false
Truncated: false
Recursion Desired: true
Recursion Available: true
Result Code: NoError
Questions (1):
A google.com
Answers (1):
google.com 287 A 142.250.80.78$ dns-rust gmail.com MX
Querying 8.8.8.8:53 for MX record of gmail.com
DNS Response:
=============
ID: 6666
Response: true
Authoritative: false
Truncated: false
Recursion Desired: true
Recursion Available: true
Result Code: NoError
Questions (1):
MX gmail.com
Answers (5):
gmail.com 3599 MX 10 alt1.gmail-smtp-in.l.google.com
gmail.com 3599 MX 20 alt2.gmail-smtp-in.l.google.com
gmail.com 3599 MX 30 alt3.gmail-smtp-in.l.google.com
gmail.com 3599 MX 40 alt4.gmail-smtp-in.l.google.com
gmail.com 3599 MX 5 gmail-smtp-in.l.google.com$ dns-rust google.com AAAA
Querying 8.8.8.8:53 for AAAA record of google.com
DNS Response:
=============
ID: 6666
Response: true
Authoritative: false
Truncated: false
Recursion Desired: true
Recursion Available: true
Result Code: NoError
Questions (1):
AAAA google.com
Answers (1):
google.com 299 AAAA 2607:f8b0:4004:c1b::65- Rust 1.70 or later
- Cargo
git clone https://github.com/yourusername/dns-rust.git
cd dns-rust
cargo buildcargo testcargo run -- google.com Adns-rust/
βββ src/
β βββ main.rs # CLI interface and main function
β βββ lib.rs # Library exports
β βββ dns.rs # Core DNS implementation
βββ Cargo.toml # Project configuration
βββ README.md # This file
βββ target/ # Build artifacts (generated)
This project can also be used as a library in your Rust projects:
[dependencies]
dns-rust = "0.1.0"use dns_rust::{lookup, QueryType};
use std::net::SocketAddr;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let server: SocketAddr = "8.8.8.8:53".parse()?;
let response = lookup("google.com", QueryType::A, server)?;
for answer in response.answers {
println!("{}", answer);
}
Ok(())
}The DNS client is built with several key components:
- BytePacketBuffer: Handles reading and writing DNS packets with proper bounds checking
- DNS Structures: Type-safe representations of DNS headers, questions, and records
- Query Engine: UDP-based DNS query implementation
- CLI Interface: User-friendly command-line interface using clap
- No unsafe code is used anywhere in the project
- Strict compiler warnings and lints are enforced
- Comprehensive bounds checking for all buffer operations
- Proper error handling throughout the codebase
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for your changes
- Ensure all tests pass (
cargo test) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Initial release
- Support for A, AAAA, NS, CNAME, and MX record types
- Command-line interface
- Comprehensive test suite
- Library API for programmatic usage