This repository contains a small DNS server implementation inspired by the tutorial provided in EmilHernvall's DNS guide. The goal of this project is to build a foundational understanding of how DNS servers operate by creating a simplified version.
- Parses DNS queries and constructs appropriate responses.
- Supports basic record types like
A,NS,CNAME,MXandAAAA. - Implements the DNS protocol as per the tutorial guidelines.
To run this project, you'll need:
- A working installation of Rust (recommended version: 3.8 or later).
-
Clone the repository:
git clone https://github.com/devdata49/dns_server.git cd dns_server -
Build the server
cargo build
-
Run the server:
cargo run
After starting the DNS server, you can test it by sending DNS queries. Use tools like dig or nslookup:
dig @127.0.0.1 -p 4500 google.comReplace 127.0.0.1 with the address where your DNS server is running and 4500 with the port number specified in your implementation.
src/
├── dns/
│ ├── buffer.rs //Implements the BytePacketBuffer
│ ├── header.rs //DnsHeader
│ ├── mod.rs
│ ├── packet.rs //DnsPacket
│ ├── question.rs //DnsQuestion
│ ├── record.rs //DnsRecord
│ ├── server.rs //DnsServer
│ ├── types.rs //common types and enums
├── lib.rs
├── main.rs
This project implements the core components of a DNS server:
- Listening for Requests: The server listens for incoming DNS queries over UDP.
- Parsing DNS Messages: It decodes DNS queries into a format the server can understand.
- Generating Responses: Based on the query, it constructs valid DNS responses.
- Responding to Clients: Sends back the response to the client using the same socket.
- Understood the basics of the DNS protocol.
- Learned how to parse from and write to a bytestream.
- Learned how DNS lookups happens behind the scenes.