Skip to content

Networking and DNSreference

knotea, a resolver and authoritative DNS server in one binary

knotea is a single Go binary that is at once an authoritative nameserver and a recursive, ad-blocking resolver - the Cloudflare model of auth and resolver behind one query path. A query for a name in a served zone is answered authoritatively; anything else is filtered (policy, then ad-block, then cache) and recursed. It owns public :53 UDP/TCP, :853 for DNS-over-TLS, and :8080 for an HTTP (Hypertext Transfer Protocol) dashboard plus DNS-over-HTTPS (Hypertext Transfer Protocol Secure), and it supervises two specialists as child processes: unbound for recursion with DNSSEC (Domain Name System Security Extensions), and knotd for the authoritative zones. RFC (Request for Comments) 2136 UPDATE and zone transfers are relayed inward to knotd.

TL;DR: One merged binary replaced two projects (glory-hole the resolver, knot-fly the authority) so the authoritative zones live in the same process as the resolver - a query for your own zone never leaves the box, which sidesteps the Fly anycast UDP (User Datagram Protocol) hairpin and failures like it. Live record edits go through <zone-cli>, a TSIG-signed RFC 21361 CLI (command-line interface). It runs on Fly.io anycast as the production nameserver for the zones it serves.

Two smaller DNS (Domain Name System) setups documented elsewhere here are close relatives of this one: the Glory-Hole DoT (DNS over TLS) / VyOS interop guide, which exposes this same resolver over DNS-over-TLS through the edge router, and Unbound + AdGuard Home on a travel router, a standalone recursive resolver for a single device class. knotea is what the resolver grew into once it also took over authoritative duty.


They started as separate projects - glory-hole (the resolver) and knot-fly (the authority) - and were merged so the authoritative data sits in the same process as the resolver. When this box is asked for one of its own zones, the query is answered locally instead of recursing out to a public resolver and back. On Fly.io it is required, because Fly blocks inbound UDP to customer-anycast IPs (Internet Protocol addresses) from inside Fly2 - so a resolver running on Fly that has to recurse to itself for a Fly-hosted zone returns SERVFAIL (server failure). Running knotd in-process on loopback removes that dependency entirely.

Both subprojects keep their full git history under their subdirectories; each still builds standalone. A root go.work links the two modules.

clientknotea:53 :853(DoT) :8080(DoH+UI)policy engineexpr rulesotherwiseknotd127.0.0.1:5354 authoritativename in served zonead-block~9M-domain listsunbound127.0.0.1:5353 recursion+DNSSECrecurse

The same path as a list:

  1. A client query arrives on :53 (UDP/TCP), :853 (DoT) or :8080 (DoH (DNS over HTTPS) and the dashboard).
  2. If the name is in a served zone, knotea answers it from knotd on 127.0.0.1:5354.
  3. Otherwise the query goes to the policy engine, which evaluates the expr rules.
  4. What the policy does not block falls through the ad-block lists (~9M domains) and recurses through unbound on 127.0.0.1:5353.

The recursive side combines ad-blocking, an expression-based policy engine, local zones, and a web dashboard in the one binary, with unbound doing the recursion and DNSSEC validation.

  • Blocklists. Downloaded, deduplicated, and atomically swapped in; exact, wildcard, and regex patterns with optional auto-update. Defaults are the hagezi and OISD lists. Whitelists short-circuit a block. Reads are lock-free (atomic.Pointer) so a list reload never stalls a query.
  • Policy engine. expr rules3 with helpers like DomainMatches, IPInCIDR, InTimeRange; actions BLOCK, ALLOW, REDIRECT, FORWARD. Compiled once, evaluated in order, with a visual builder and tester in the UI (user interface).
  • Upstream health. A circuit breaker on the forwarder (opens after consecutive failures, half-opens to probe), plus one TCP (Transmission Control Protocol) retry after a UDP SERVFAIL - that retry exists specifically to work around the Fly UDP hairpin block.
  • Telemetry. Prometheus on :9090/metrics, a SQLite query log (WAL, batched async writes), and host CPU/memory/temperature (central processing unit) in the dashboard. The dashboard is Astro + React, embedded with go:embed.

Measured (from the repo’s perf harness): a full-handler profile of 166 ns/op at 7 allocs - the UDP socket saturates long before the Go code does. Same-region latency: cached UDP around 4.3 ms, cold recursion around 4.0 ms, DoH warm 3 ms at p50, a fresh DoT handshake around 19.6 ms. ECDSA (Elliptic Curve Digital Signature Algorithm) P-256 DoT handshakes run about 1.8x the rate of RSA-2048 (Rivest-Shamir-Adleman), which is why the cert type changed.

knotd (Knot DNS)4 serves the two zones, both DNSSEC-signed and validating - ECDSAP256SHA256 with KSK (key signing key) and ZSK (zone-signing key), online signing, DS (delegation signer) records published at the parent. Zone data is operator state held in knotd’s confdb and journal, added at runtime; the declarative source of truth is a set of YAML (YAML Ain’t Markup Language) zonefiles reconciled onto the server.

TSIG (Transaction Signature) keys are scoped by role, so no consumer holds more power than it needs:

KeyMay update
caddy-acme._acme-challenge.* TXT (text) only (the ACME DNS-01 path)
caddy-ddns.A/AAAA (IPv6 address record) dynamic updates
<zone-cli>.general operator records
axfr-out.outbound zone transfers to secondaries

Since knotea 1.5.3 (2026-10-30) a served zone can be hidden. knotd keeps the zone and serves it to TSIG-authenticated secondaries, but knotea never answers it on a query path: the zone is left out of authoritative routing and out of the client ACL (access control list), so a query for it takes the ordinary path (refusal for an unknown client, recursion to the public delegation for an allowed one) and never reaches knotd. Two per-zone zone_apex options drive it:

OptionDefaultEffect
hidden: truefalseknotea answers nothing for the zone from knotd; the zone must also be in served_zones
sign: falsetruethe zone is created without DNSSEC (reconcile is create-only, so an existing zone is never re-keyed or unsigned)

zone_apex.default may set neither, because it is the fallback for every zone without its own entry: one line there would hide or unsign all of them.

The point is a hidden primary: the zone’s records stay in git with every other zone, while its public nameservers are a separate secondary on an address that serves nothing else. The full design, and why it needs a separate host, is in Running a domain that does not link back to you.

What reaches knotd through the TCP relay, before the query path: RFC 2136 UPDATE, NOTIFY, AXFR/IXFR, and (since 1.5.4) TSIG-signed SOA (start of authority) queries. The last one exists because a secondary’s refresh starts with a signed SOA query; without it the secondary could bootstrap a hidden zone over AXFR (authoritative zone transfer) but never refresh it. knotd verifies the signature before any zone lookup, so a wrong key gets NOTAUTH (not authoritative) for every zone, served or not, and the relay is not an oracle for which zones exist (measured 2026-10-30).

<zone-cli> is the operator CLI. It speaks TSIG-signed RFC 2136 UPDATE1 to the server’s public :53, which the resolver relays byte-for-byte to the loopback knotd.

Terminal window
<zone-cli> add www.example.com A 192.0.2.10
<zone-cli> ls example.com
<zone-cli> set example.com TXT "v=spf1 -all"
<zone-cli> apply zones/example.com.yml --prune

Subcommands: add, rm, set, ls, apply, export, keys. Three of them do more than their name says:

  • add polls until the record is queryable and exits non-zero on timeout - so a script that chains on it does not race the zone.
  • set bundles the delete-rrset and the new records into one UPDATE message, so there is no empty or partial window.
  • apply reconciles declarative YAML - additive by default, --prune removes drift, and it never touches apex NS (name server), SOA, or DNSSEC records. Idempotent; multi-value rrsets are atomic.

Key material lives one-file-per-identity under ~/.config/<zone-cli>/keys/, mode 0600 or it is refused. Never pass a secret with -y on the command line - it lands in shell history.

Runs as a single Fly.io app (region sin) on anycast.2 The port mapping: 80 to the dashboard, 443 to app-terminated TLS (Transport Layer Security), 53 UDP/TCP, 853 DoT. One shared-cpu VM (virtual machine) with 1 GB and GOMEMLIMIT=768MiB (raised from 512 MB in October 2026 after the daily blocklist refresh pushed the process past the old limit and the machine was OOM-killed (out of memory) twice). Fly machines pull images server-side and cannot authenticate to ghcr, so deploys pull the CI-built (continuous integration) image, retag to the Fly registry, push, and deploy by image reference.

A second instance of the same image runs on the edge router as the LAN (local area network) resolver, with the authority half off. It answers plain DNS, DoT and DoH for every LAN client, and the router redirects port-53 traffic aimed at public resolvers to it; the steering design is in NixOS edge router network design. Its DoT listener is bound to the service-plane address, not :853, because the router’s WAN (wide area network) interface is on the same host.

The serving authority moved once more on 2026-09-18, in a blue-green cutover. The original app kept serving while a second Fly app stood up on a dedicated anycast address with a fresh volume and the repo-managed seed; once every zone was verified serving from the new app, the TLD (top-level domain) glue and the DS records flipped to it in the registrar config, and the original app was retired the same day - machine destroyed, its dedicated anycast released. The released address cannot be re-allocated, so a rollback is the cutover re-run in reverse (new machine, new address, glue and DS repointed), rather than a pointer flip. Keeping the registrar side as code is what makes that tolerable: the serving address is a single local in the OpenTofu config, so the next cutover changes that one local in the same commit that moves the NS. Daily backups of the non-regeneratable state (KASP (Key and Signature Policy) signing keys, timers, confdb export) land on R2 with 14-day retention, and the rebuild runbook is drill-tested against a scratch app.

The registrar layer: domain registration, authoritative DNS, and the edge

Section titled “The registrar layer: domain registration, authoritative DNS, and the edge”

A self-hosted DNS setup spans three independently-operated layers, each in a different repo and run by a different tool:

LayerOwnsRun byRepo
Domain registrationNS delegation, glue records, DS records at the TLDOpenTofu + Porkbun API5infra/dns-tf
Authoritative DNSZone data, DNSSEC signing, TSIG keysknotd inside knotea (Fly.io anycast)infra/knotea
Edge proxyTLS termination, ACME DNS-01 challenges, reverse proxyCaddy on the NixOS edge routerinfra/router

The split keeps failures from cascading: a Caddy restart does not touch the authoritative zone, and a registrar-side glue push is independent of what knotd serves. The coupling points are narrow - the edge proxy calls <zone-cli> over TSIG-authenticated RFC 2136 for ACME (Automated Certificate Management Environment) challenges, and the registrar layer holds the NS, glue and DS that point at the authority. Changing the serving anycast address means changing one local.knotea_anycast_v4 in main.tf and re-applying, rather than editing records across every zone.

On 2026-09-05 the erfi.io zone stopped resolving. The registrar’s glue-record push to the TLD registry silently failed: the registrar UI displayed the NS A records as present, but the registry held the delegation with no A records attached. Because the nameservers are in-bailiwick (ns1.erfi.io), recursive resolvers deadlocked:

  1. A resolver follows the referral from the TLD: ask ns1.erfi.io.
  2. To ask ns1.erfi.io, the resolver must resolve its IP address.
  3. Resolving ns1.erfi.io’s IP means querying the authoritative nameserver for erfi.io.
  4. That nameserver IS ns1.erfi.io - a loop.

The glue A record in the referral breaks the cycle. Without it, no recursive resolver could resolve the zone. The outage was diagnosed by querying the TLD registry directly: dig @a0.nic.io ns1.erfi.io A showed the NS record with no address in the ADDITIONAL section. The fix was a glue re-push from the registrar, which landed within hours.

The same day, 12 domains migrated from Namecheap to Porkbun. Namecheap’s UI showed the glue as pushed while the registry never received it - the same silent-failure gap - and the registrar-side state had no independent verification path. Porkbun was chosen after an audit of the registrars that had an API (application programming interface), an OpenTofu provider (the vitvio/porkbun provider6), and no known silent-failure history. servarr.io and servarr.dev were bought at Porkbun on 2026-09-14.

Registrar as infrastructure: Porkbun via OpenTofu

Section titled “Registrar as infrastructure: Porkbun via OpenTofu”

The registrar side of every domain is now declarative OpenTofu: per-domain NS, glue A records, and DS records are state in git, imported from the live Porkbun account. The serving anycast address is centralised in one Terraform local (local.knotea_anycast_v4), so a future cutover changes one value in main.tf.

State (terraform.tfstate, terraform.tfstate.backup) and secrets (secrets.tfvars) are committed SOPS-encrypted7 with the same age key. A pre-commit hook blocks plaintext .tfvars and .tfstate files.

The verification that matters is at the registry, not at the registrar API. The registrar can report the glue as pushed while the TLD never received it - the 2026-09-05 failure was exactly that gap. The checked-in verification queries the TLD registry directly:

Terminal window
dig @a0.nic.io ns1.erfi.io A | grep '137.66.57.23'

This checks the ADDITIONAL section rather than +short, which hides in-bailiwick glue. For DNSSEC, dig +dnssec erfi.io SOA @1.1.1.1 confirms the ad flag is set.

The cutover method: blue-green with glue and DS re-pin

Section titled “The cutover method: blue-green with glue and DS re-pin”

Changing the serving Fly app is a blue-green cutover. The existing app keeps serving while a new Fly app stands up on a dedicated anycast address with a fresh volume and a repo-managed zone seed. Once every zone is verified serving from the new app, two things happen in the same OpenTofu apply:

  1. The local.knotea_anycast_v4 value flips to the new anycast address.
  2. The DS records are re-pinned to the new app’s live KSK CDS (child delegation signer), read with <zone-cli> ds <zone> and matched against dig CDS <zone> @<new-ip>.

The cutover is verified with dnsviz8, a DNSSEC chain visualisation that shows the delegation, the DS at the parent, and the RRSIG (resource record signature) chain from the zone’s keys. The previous cutover on 2026-09-18 replaced the glory-hole app (137.66.1.170) with knotea on a new dedicated anycast (137.66.57.23). The old anycast address was released the same day - Fly dedicated anycast addresses cannot be re-allocated, so a rollback is a re-run of the cutover in reverse (new machine, new address, glue and DS repointed), not a pointer flip.

SOPS/OpenTofu gotcha: one file per invocation

Section titled “SOPS/OpenTofu gotcha: one file per invocation”

SOPS (Secrets OPerationS) 3.13.3 takes only the first positional argument and warns: “More than one positional argument provided. Only the first one will be used!” Running sops -e -i --age $AGE file1 file2 encrypts file1 and silently leaves file2 in plaintext. Both terraform.tfstate and terraform.tfstate.backup are committed encrypted, and a script that encrypts them in a single invocation leaks the backup file in plaintext into the repo.

The fix is a per-file loop:

Terminal window
for f in terraform.tfstate terraform.tfstate.backup; do sops -e -i --age $AGE "$f"; done

The pre-commit hook blocks plaintext .tfstate files, so a leak is caught before it is committed, but the sops invocation must not rely on the hook as the first line of defence.

The zones were moved off Cloudflare by mirroring over AXFR (CF Enterprise can do outgoing transfers to a TSIG peer), then promoting Knot to primary and swapping the registry NS records. The full runbook is in the authority subproject’s docs.

  • Cloudflare’s documented NOTIFY source IPs are wrong. NOTIFYs arrive from CF (Cloudflare)‘s full anycast ranges plus Fly-internal ranges. Allowlist the runtime-fetched CF list, or Knot logs ACL, denied, action notify and your IXFR (incremental zone transfer) silently falls behind.
  • The first CF AXFR returns BADKEY for about 30 seconds. Wait it out; do not roll back.
  • The registry NS swap is the one irreversible-until-TTL step. Everything before it is a no-op to roll back; after it you wait out the parent TTL (time to live). Add the new NS alongside the old and verify before removing, rather than a full swap.
  • Any Caddy site still on dns cloudflare breaks silently once recursive caches expire after the cutover - migrate every site block to the dns rfc2136 provider within the TTL soak window.
  • TSIG rotation is confdb-first. knotd’s confdb is the source of truth; rotate there before consumer stores, verify the old key gets BADSIG, and only then clean up. A past incident baked live TSIG secrets into config comment lines for ~29h via a sed that matched placeholders in comments - the entrypoint now fails closed if a secret appears in a comment.
  • knotc conf-set is runtime-only in file mode; run knotd with -C <confdb-dir>4 or your changes vanish on restart.
  • sub-or-equal does not match ACME owners. update-owner-match: sub-or-equal does not match _acme-challenge.<host> - use a pattern covering _acme-challenge and its wildcard forms.
  • A zone-level acl replaces the template’s list, and conf-set on a list appends. Giving one zone its own transfer ACL drops the template’s axfr_out and zonectl_update unless you list them again, and setting a list item that already has values adds to it. Unset the item first, then set the full list in one transaction.
  • Apex NS and SOA cannot change over UPDATE. knotd answered REFUSED to an apex NS replacement sent as RFC 2136 UPDATE (measured; the RFC itself only makes those sets undeletable); use knotc zone-begin / zone-set / zone-commit on the server with a SOA serial above the current one. For a hidden zone, <zone-cli> apply also reports REFUSED on its read-back verify after a correct write, because the read-back is a public query; check drift with --dry-run.
  • Single region is a SPOF (single point of failure). A second Knot machine pulling over Fly’s internal network is the recorded plan, not yet built.
  • RFC 2136 ACME against a remote knotea fails with NOTIMP (not implemented). The built-in DNS-01 path uses lego’s RFC 2136 provider, which sends the UPDATE over UDP; the public knotea relays UPDATE to knotd only on its TCP listener. A rehearsal for the LAN instance’s DoT certificate got replied NOTIMP for INSERT (measured, November 2026). Caddy’s RFC 2136 plugin issues fine against the same server, which is consistent with it sending UPDATE over TCP. Until the provider can be told to use TCP, the LAN DoT listener uses a self-signed certificate.
  • After a cutover, verify a fresh issuance, not just the surviving certificates. The first new certificate issued after the September 2026 edge-proxy cutover failed with dns: bad authentication: the ACME TSIG key in the router’s secret store was a rotated-out value, and because the certificate store had been preserved through the cutover, nothing on the new binary had exercised the RFC 2136 path. The cutover checklist only checked already-issued certificates; a throwaway vhost’s certificate is what proves the path end to end.

The latency figures above are same-region (client and server both in sin), so they are the floor: a resolver on anycast is only that fast for a client near a PoP (point of presence), and cross-region recursion is distance-dominated the same way any round trip is. The 166 ns/op handler profile is a single-core microbenchmark; it shows the Go code is not the bottleneck, and it does not show the box sustains that rate, because the UDP socket and the harness saturate first. Base capacity sizing on UDP socket and network throughput.

Measured rows come from the monorepo’s own perf-harness notes, same-region (client and server both in sin) unless the row says otherwise. The blue-green row is an operator record, not a measurement.

ClaimHow it was checkedStatus
Full-handler profile 166 ns/op at 7 allocsrepo perf harness, full-handler profilemeasured
Cached UDP ~4.3 ms, cold recursion ~4.0 msrepo perf harnessmeasured
DoH warm 3 ms at p50repo perf harnessmeasured
Fresh DoT handshake ~19.6 msrepo perf harnessmeasured
ECDSA P-256 DoT handshakes ~1.8x the RSA-2048 raterepo perf harnessmeasured
The serving authority moved to a new Fly app on 2026-09-18, glue and DS flipped per zoneoperator record of the cutoverdated event
Daily backups of KASP signing keys, timers and the confdb export to R2, 14-day retention, rebuild runbook drill-tested against a scratch apprepo docsdocumented
A second Knot machine pulling over Fly’s internal networkrecorded plandesign only
Hidden zone answers REFUSED on the public port, UDP and TCP; bad TSIG gets NOTAUTH for hidden, public and non-existent zones alikedig from the internet, 2026-10-30measured
A secondary refreshes a hidden zone over the TCP relay after the 1.5.4 SOA changesecondary’s log: refresh REFUSED before, “zone is up-to-date” aftermeasured

Run knotea (or this auth+resolver-in-one pattern) when you want your own zones and your recursive/filtering DNS under one roof with one deploy, and you are comfortable operating DNSSEC and TSIG yourself. Do not take on the authoritative half just to get ad-blocking - if all you want is filtered recursive DNS for clients, the Unbound + AdGuard Home travel-router setup is far less to run, and if you only need to expose the resolver over DoT through an edge router, the VyOS interop guide covers that without touching authoritative DNS.

  1. P. Vixie et al., “Dynamic Updates in the Domain Name System (DNS UPDATE),” RFC 2136, IETF. https://www.rfc-editor.org/rfc/rfc2136 ↩ ↩2

  2. Fly.io, “Networking on Fly.io (anycast, public/private networking).” https://fly.io/docs/networking/ ↩ ↩2

  3. expr-lang, “expr - expression language for Go.” https://expr-lang.org ↩

  4. CZ.NIC, “Knot DNS 3.5 Documentation - Configuration (confdb, TSIG keys, dynamic updates).” https://www.knot-dns.cz/docs/3.5/singlehtml/index.html ↩ ↩2

  5. Porkbun, “Porkbun API v3 - v3.84,” Porkbun. https://porkbun.com/api/json/v3/documentation ↩

  6. vitvio, “terraform-provider-porkbun,” GitHub. https://github.com/vitvio/terraform-provider-porkbun ↩

  7. Mozilla / Getsops, “SOPS: Secrets OPerationS.” https://getsops.io ↩

  8. Sandia National Laboratories, “DNSViz - A DNS visualization tool.” https://dnsviz.net ↩