A recursive DNS server in C++20 with thread-safe LRU caching and dual-stack IPv4/IPv6 support.
- 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
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --parallel $(nproc)- CMake 3.20+
- GCC 10+ or Clang 12+ (C++20 support)
cd build
ctest --output-on-failure./dns_server [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 | — |
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 build -t dns-server .
docker run -p 53:53/udp dns-serverBSD 2-Clause