Forwarding and recursion¶
This page shows how to let Ninlil answer queries for names it does not host. It can find the answer in two ways:
- Forwarding. Ninlil sends the query to one or more forwarders, DNS servers you name, and relays the answer.
- Recursion. Ninlil asks the servers of the DNS tree itself, starting at the root servers and following the delegations down to the server that holds the answer.
Both are off by default, because a server that answers anyone can be misused in an attack. A query reaches them in this order: a name inside a zone Ninlil hosts is answered from the zone, otherwise Ninlil tries forwarding if it is on, and if no forwarder answered it tries recursion if that is on. Ninlil validates DNSSEC for forwarded and recursive answers.
Before you start¶
- A running Ninlil and a signed-in API token, as in Zones and records
"Before you start". The commands use the Quick start values: the API on
https://127.0.0.1:18443and DNS on port15300.<token>is theaccessTokenvalue. - A user that holds the
recursivesettings:write,forwardingsettings:write,forwarders:write,zones:writeandaccesscontrol:writepermissions. -
dig, and an upstream server that Ninlil can reach on UDP and TCP port 53. This page uses the public resolver Quad9 (9.9.9.9and149.112.112.112). Check that it answers from this host:dig @9.9.9.9 example.com A +short104.20.23.154 172.66.147.243Your addresses differ. No output and a
timed outmessage mean a firewall blocks the path.
The examples call the API on 127.0.0.1 with curl -k, which skips the certificate check.
That is safe only on the machine that runs Ninlil; see Self-signed certificate.
Steps¶
Allow recursive service¶
A client gets recursive service when its query has the RD (recursion desired) bit set, which every
stub resolver sets, and the client is permitted recursion. Ninlil answers any other client's
query for a name it does not host with REFUSED. Choose one of two ways.
-
To serve every client, turn recursion on (
NINLIL_DNS_SERVER_RECURSIVE_ENABLE_RECURSION). The change takes effect at once, but the configuration reload can take about a second:curl -k -X PATCH https://127.0.0.1:18443/api/recursive-settings -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"enableRecursion":true}'{"note":"Written to the configuration file. This setting is read live, so it takes effect immediately -- no restart required."}In the console: Presets & Settings, Recursive Resolver, tick Recurse for a query this server does not itself host and save. 2. To serve only some clients, leave recursion off and add an access rule instead. The
cidris an address or a network such as192.168.1.0/24:curl -k https://127.0.0.1:18443/api/access-control-rules -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"name":"Local network","cidr":"127.0.0.1","capabilities":["RecursionAccess"]}'{"id":"...","name":"Local network","cidr":"127.0.0.1","capabilities":["RecursionAccess"],"isDisabled":false, ...In the console: Access Control Rules, New rule. The
digcommands on this page come from127.0.0.1, so this rule serves them.
Forward to global forwarders¶
Global forwarders are a list that Ninlil tries in order for every name.
-
Turn forwarding on:
curl -k -X PATCH https://127.0.0.1:18443/api/forwarding-settings -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"enable":true}'In the console: Presets & Settings, Forwarding. The variable is
NINLIL_DNS_SERVER_FORWARDING_ENABLE. 4. Add a forwarder.definitionStringsays where to send queries.sortOrderputs the forwarder in line: lower values go first:curl -k https://127.0.0.1:18443/api/forwarders -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"name":"quad9","definitionString":"9.9.9.9","sortOrder":0}' curl -k https://127.0.0.1:18443/api/forwarders -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"name":"quad9-secondary","definitionString":"149.112.112.112","sortOrder":1}'{"id":"...","name":"quad9","definitionString":"9.9.9.9","protocol":"Plain","sortOrder":0,"isDisabled":false, ...In the console: Forwarders, New forwarder. The form offers well-known public resolvers in a list and a field for a definition you type. These are the forms of
definitionString:definitionStringMeaning 9.9.9.9or9.9.9.9:53Plain DNS over UDP, with TCP when an answer is truncated. udp://andtcp://in front mean the same.[2620:fe::fe]:53Plain DNS over IPv6. A port after an IPv6 address needs brackets. tls://dns.quad9.netDNS-over-TLS, port 853 unless you add :<port>. The host name is also the name Ninlil expects in the server's certificate.https://dns.quad9.net/dns-queryDNS-over-HTTPS. quic://dns.example.netDNS-over-QUIC, port 853 unless you add :<port>. Needslibmsquic2.4.20 or later on the host.sdns://...A DNSCrypt stamp. See Encrypted transports and DNS64. Ninlil checks the syntax when you save and never looks a host name up at that point. A definition it cannot parse answers
400with the reason.
Forward one domain to its own servers¶
A zone of the type Forwarder sends the names at and below its own name to its own list of servers
instead of the global list. Use one to send a private domain such as corp.example to the servers
that know it. The closest enabled zone above the queried name wins.
-
Create the zone. This example sends
corp.exampleand every name below it to192.0.2.53. Use the address of a server you run. The forms are the ones in the table above:curl -k https://127.0.0.1:18443/api/zones -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"name":"corp.example","type":"Forwarder","forwarderAddresses":["192.0.2.53"]}'{"id":"<forwarder-zone-id>","name":"corp.example","type":"Forwarder", ... "forwarderAddresses":["192.0.2.53"], ...Copy the
idas<forwarder-zone-id>. In the console: Zones, New zone, type Forwarder. 6. The zone hasvalidateDnssecoff, which is right for a private domain. Turn it on only for a domain that is signed under the public root:curl -k -X PATCH https://127.0.0.1:18443/api/zones/<forwarder-zone-id> -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"validateDnssec":true}'
Let a private domain pass DNSSEC validation¶
-
DNSSEC validation is on by default. A private domain has no chain of trust from the public root, so validation fails for it. Put the domain on the Insecure domains list. A name at or below an entry skips validation and is answered without the AD bit, so a forged answer for such a name is accepted: list only domains you control. Saving a list replaces the built-in one, so repeat the built-in names you still need (
home.arpaandinternalhere):curl -k -X PATCH https://127.0.0.1:18443/api/recursive-settings -H 'Authorization: Bearer <token>' -H 'Content-Type: application/json' -d '{"insecureDomains":["corp.example","home.arpa","internal"]}'To go back to the built-in list, send
{"insecureDomains":null}. The console has the list under Presets & Settings, Recursive Resolver, with a Restore defaults button.
Look at the caches and flush them¶
-
List this node's DNS caches, with sizes and hit counts:
curl -k https://127.0.0.1:18443/api/dns-cache -H 'Authorization: Bearer <token>'[{"name":"dnssec","entryCount":5,"maxEntries":10000,"hits":2,"misses":5},{"name":"forwarded","entryCount":5,"maxEntries":10000,"hits":1,"misses":6},{"name":"recursive","entryCount":84,"maxEntries":100000,"hits":276,"misses":119}] -
Forget one name in every cache, or empty every cache. Both need the
recursivesettings:writepermission and neither touches another cluster node. The answer is the number of entries removed (your counts differ):curl -k -X DELETE https://127.0.0.1:18443/api/dns-cache/entries/example.com -H 'Authorization: Bearer <token>' curl -k -X DELETE https://127.0.0.1:18443/api/dns-cache -H 'Authorization: Bearer <token>'{"removedEntryCount":5} {"removedEntryCount":89}
Check that it worked¶
-
Ask Ninlil for a name it does not host:
dig @127.0.0.1 -p 15300 example.com A +noall +comments +answer;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22877 ;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1 example.com. 300 IN A 104.20.23.154 example.com. 300 IN A 172.66.147.243(Trimmed to the lines that matter. Your numbers and addresses differ.)
NOERRORand an answer mean Ninlil found the name. The flagra(recursion available) shows the client is served.ad(authentic data) shows Ninlil validated the answer with DNSSEC. A name in an unsigned zone has noad. 2. Ask again after a few seconds. The TTL counts down, because Ninlil answers from its cache. 3. For a conditional forwarder zone, ask for a name below it. A name that the zone's servers know gets their answer, withoutadwhilevalidateDnssecis off:dig @127.0.0.1 -p 15300 intranet.corp.example A +noall +comments +answer;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 intranet.corp.example. 300 IN A 192.0.2.53 -
A client that is not permitted recursion gets
status: REFUSED. To see that, turnenableRecursionoff, remove the access rules and ask again.
Good to know¶
- Forwarders are tried in order. A forwarder has failed when it does not answer within 3 seconds or
answers with any code except
NOERRORandNXDOMAIN. Then Ninlil asks the next one. When every forwarder has failed, Ninlil falls back to recursion if the client may use it. - The default failover strategy,
HealthCheckedRoundRobin, takes turns among the healthy forwarders and leaves out one that failed three queries or probes in a row.TryInOrderalways starts with the first. - A forwarder given as a host name is looked up in the background, by the operating system's resolver, and a query never waits for it. On a server whose own system resolver is Ninlil, give the forwarders as addresses.
- A conditional forwarder zone replaces the global list for the names below it.
- With validation on, a forwarded answer that fails DNSSEC counts as a failure of that forwarder. A
private name behind an unsigned conditional forwarder zone then gets the public DNS's
NXDOMAINunless the name is on the Insecure domains list. - Recursion uses QNAME minimization (RFC 9156), serves an expired answer when servers are unreachable
(RFC 8767) and keeps the root trust anchors up to date (RFC 5011). A network that blocks DNSSEC
data needs
NINLIL_DNS_SERVER_RECURSIVE_ENABLE_DNSSEC_VALIDATION=false, or clients getSERVFAIL. With validation off, Ninlil does not check the DNSSEC signatures of recursive and forwarded answers, so a forged answer is accepted. Turn it off only on a network that blocks DNSSEC data. - The README holds the full rules: Forwarding and recursion.
When something goes wrong¶
- Every query answers
REFUSED. The client is not permitted recursion. Turn onenableRecursionor add an access rule for the client's address, and wait a few seconds. digsaysrecursion requested but not available. The same cause: the reply carries noraflag.- The answer is
SERVFAIL. Validation failed or no server answered. Read the Ninlil log forBogusorForwarderlines. If a private zone is the cause, add it to the Insecure domains list. If your network blocks DNSSEC data, turn validation off. 400"'[::1' is not a valid forwarder definition: '[::1' carries a malformed bracketed IPv6 address." Close the bracket:[::1]:53.- A forwarder you added seems ignored. A forwarder earlier in the order, or a conditional zone,
answers first. List the forwarders with
GET /api/forwardersand look atsortOrder. - A cached answer is stale after you changed upstream data. Forget the name with the commands in step 9.
Next¶
- Filtering, rewrites and parental controls: block or rewrite what clients ask for.
- Encrypted transports and DNS64: forward over TLS, HTTPS, QUIC or DNSCrypt, and synthesize AAAA records.