Skip to content

This repository contains a small DNS server implementation inspired by the tutorial provided in EmilHernvall's DNS guide.

Notifications You must be signed in to change notification settings

DevData49/dns_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DNS Server Implementation

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.

Features

  • Parses DNS queries and constructs appropriate responses.
  • Supports basic record types like A, NS, CNAME, MX and AAAA.
  • Implements the DNS protocol as per the tutorial guidelines.

Getting Started

Prerequisites

To run this project, you'll need:

  • A working installation of Rust (recommended version: 3.8 or later).

Installation

  1. Clone the repository:

    git clone https://github.com/devdata49/dns_server.git
    cd dns_server
  2. Build the server

    cargo build
  3. Run the server:

    cargo run

Usage

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.com

Replace 127.0.0.1 with the address where your DNS server is running and 4500 with the port number specified in your implementation.

Project Structure

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:

  1. Listening for Requests: The server listens for incoming DNS queries over UDP.
  2. Parsing DNS Messages: It decodes DNS queries into a format the server can understand.
  3. Generating Responses: Based on the query, it constructs valid DNS responses.
  4. Responding to Clients: Sends back the response to the client using the same socket.

Learning Outcomes

  • 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.

References

About

This repository contains a small DNS server implementation inspired by the tutorial provided in EmilHernvall's DNS guide.

Resources

Stars

Watchers

Forks

Languages