Skip to content

scorpiondefense/dns_server

Repository files navigation

DNS Server

A recursive DNS server in C++20 with thread-safe LRU caching and dual-stack IPv4/IPv6 support.

Features

  • RFC 1035 compliant DNS wire format parsing and serialization with compression pointer support
  • Thread-safe LRU cache with TTL-based expiration and background cleanup
  • Dual-stack networking — simultaneous IPv4 and IPv6 listening
  • Upstream forwarding — configurable upstream resolvers (default: Cloudflare 1.1.1.1, Google 8.8.8.8)
  • Record types — A, AAAA, CNAME, MX, NS, TXT, SOA, PTR, ANY
  • Server statistics — real-time tracking of queries, cache hits, forwards, and errors
  • Zero external dependencies — pure C++20 with only system libraries

Building

mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --parallel $(nproc)

Requirements

  • CMake 3.20+
  • GCC 10+ or Clang 12+ (C++20 support)

Running Tests

cd build
ctest --output-on-failure

Usage

./dns_server [options]

Options

Flag Description Default
--port Listening port 53
--bind4 IPv4 bind address 0.0.0.0
--bind6 IPv6 bind address ::
--cache-size Maximum cache entries 10000
--timeout Upstream query timeout (ms) 3000
--no-ipv4 Disable IPv4
--no-ipv6 Disable IPv6

Architecture

src/
├── message.cpp      # DNS wire format codec
├── cache.cpp        # Thread-safe LRU cache with TTL
├── resolver.cpp     # Upstream query handler
└── server.cpp       # UDP server orchestrator

Docker

docker build -t dns-server .
docker run -p 53:53/udp dns-server

License

BSD 2-Clause

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors