Skip to content
HS®
All projects

(006) / 012

AuroraDNS

A DNS forwarding server written from scratch in TypeScript: RFC 1035 packets parsed with raw Buffers and bitwise operations, no parsing libraries.

Category
Networking · Systems
Year
2026
Last pushed
Aug 2026
Primary language
TypeScript
HEADER · 12 BYTES41151BA1B440303278A0D80863541B37D31E35A4275FEC0C3CAEBF4460D97C3E6D840D8702BD98540C3C4050C00C171E22C1144854BA92E00D6792673BAD74751FB0AC29CCF437AF8A2CFE8F85EC9B9D0xC0 → POINTER TO OFFSET 12
Conceptual diagram — the bytes of a DNS message, with the 12-byte header and a compression pointer marked.

(01) Overview

AuroraDNS is a lightweight DNS forwarding server built from scratch in TypeScript. Unlike most Node.js DNS servers, it does not rely on a parsing package: it reads and writes binary DNS packets (RFC 1035) directly with raw Buffers and bitwise operations.

On top of the protocol layer it adds a TTL-aware cache, failover across upstream resolvers and a small ad-blocking blocklist.

(02) Problem statement

DNS is one of those protocols most engineers use every second and never look at. The aim was to understand it at the byte level — headers, flags, questions, answers and name compression — by implementing a server that real tools like nslookup and dig can talk to.

(03) Technical approach

  • Parse by hand. Separate encoders and decoders for the 12-byte header, the question section and answer records.
  • Forward, don't recurse. Cache misses go to a configurable list of upstream resolvers.
  • Keep it small. No runtime parsing dependencies; configuration through a .env file and a plain-text blocklist.

(04) System architecture

Client-to-resolver request flowConceptual diagram · select a stage

Stage 01 — Client query

A UDP datagram arrives on the local port (2053 by default).

(05) Implementation details

The header parser unpacks the flag bits — query/response, opcode, recursion flags and response code — with shifts and masks. The question parser handles domain-name decompression: when the top two bits of a length byte are set (0xC0), the remaining bits are a pointer to an earlier offset in the packet, and the name continues from there.

Upstream responses are stored in memory by their TTL and repeat queries are answered without a round trip. A periodic sweep removes expired entries. Blocking a domain in blocklist.txt also blocks its subdomains; matches are answered with 0.0.0.0.

(06) Main features

  1. 01Hand-written encoders and decoders for DNS headers, questions and answers.
  2. 02Domain-name decompression, following 0xC0 pointers.
  3. 03TTL-aware in-memory cache with a periodic sweep of expired entries.
  4. 04Failover across a configurable list of upstream resolvers, with timeouts.
  5. 05Blocklist that answers matching domains and their subdomains with 0.0.0.0.
  6. 06Unit tests for the binary parsing logic.

(07) Technology stack

TypeScriptNode.js (dgram / Buffer)VitestDockerDocker Compose

(08) Engineering challenges

  • Compression pointers. Names can jump backwards through the packet, so the parser has to follow pointers without losing track of where the current record ends.
  • Bit-level correctness. One wrong shift in the header yields a packet that clients silently discard, which is why the binary parsing is the part covered by unit tests.
  • Unreliable upstreams. UDP gives no delivery guarantee; each upstream query has a timeout before the next resolver is tried.

(09) Evaluation and results

The parsing logic for headers, questions and answers is covered by Vitest unit tests, and the server can be exercised manually with nslookup or dig against its local port. The repository publishes no latency or throughput measurements, so none are claimed here.

Links