Ninlil answers names from a configurable list of hosts files and reloads them when they change #173

Open
opened 2026-10-31 12:42:20 -04:00 by claude · 0 comments
Owner
  • Draft: PN-29
  • Priority: medium (the main migration path from hosts-file based setups)
  • Agent: none (epic)
  • Depends on: none
  • Decisions: Q-PN-11, R2-BARE, R2-HOSTS-DEF, R2-MS-HOSTS

Why

Nothing reads a hosts file for resolution. DnsFilterListParser (src/dotnet/src/Ninlil.Dns.Server.Filtering/DnsFilterListParser.cs:88-226) reads the hosts format only to build block lists. The owner wants a list of hosts files that Ninlil answers from directly, the way a common lightweight DNS forwarder's "additional hosts" option works. The behaviour below comes from that tool's public manual page only, never its source, and the tool is not named in code, docs or commits.

What changes

The design, so every child agrees:

  • Setting. HostsFilesOptions (section DnsServer:HostsFiles):
    • Paths: a list of absolute paths, empty by default (R2-HOSTS-DEF). A path to a directory means every regular file directly in it, read in name order (not recursive).
    • ExpandDomain: a domain, or empty for off. When set, a bare name (no dot) in a file also answers as <name>.<ExpandDomain>.
    • TimeToLiveSeconds: default 60 (R2-HOSTS-DEF).
    • PollInterval: default 30 seconds.
    • Empty Paths means a new install answers nothing from /etc/hosts until the operator adds it. Ninlil's own host file would otherwise publish localhost and the machine's private names to the LAN. The README shows how to add /etc/hosts.
    • Paths is a list, so it has no environment variable (AGENTS.md "Configuration"); the other three have.
  • Loading. Every file is parsed in the hosts(5) layout (address, canonical name, aliases, # comments). The result is one immutable table swapped in atomically, so a query never sees a half-loaded table.
    • A file that cannot be read keeps its last good entries and reports an error in the status.
    • Size and entry caps protect memory.
    • Reload on change uses a file-system watcher plus a size-and-modification-time poll every PollInterval. Technical call: watchers miss events on network file systems and some bind mounts, so the poll is the guarantee and the watcher only makes it faster.
  • Answering multi-label names. A new IDnsQueryResolver, registered after the authoritative resolvers and before forwarding (Program.cs:496-503):
    • A and AAAA answers for every address a name has, across all files (the <name>.<ExpandDomain> forms included).
    • PTR for in-addr.arpa and ip6.arpa (RFC 1035 §3.5, RFC 3596 §2.5) answers the first name listed for that address, in path-list order; with ExpandDomain set, a bare name answers as its expanded form.
    • An A or AAAA question for a hosts name that has no address of that family gets NODATA (RFC 2308 §2.2), so the local name does not leak upstream. Other types pass to the next resolver, so a hosts entry that overrides a public name does not break its MX or TXT.
    • Technical call: as a resolver it runs after filtering and rewrites (DnsQueryProcessingPipeline.cs:56-63), so block lists and rewrites still apply, and an authoritative zone the operator hosts wins over a hosts file.
  • Answering bare (single-label) names (R2-BARE). The resolver does not answer a single-label query itself. The hosts files are the second source in #136's bare-name chain (LocalHostNameSourceOrder.HostsFiles): DHCP-registered names (#137) first, then the hosts files, then the local domain (#138), then NXDOMAIN (or upstream when single-label protection is off). So a DHCP client's registered name wins over a stale hosts entry, as the owner ordered.
  • Scope. Per node: a path names a file on one machine, so the setting is not cluster-synced. No per-client scoping (rewrites already do that).

Children: #174 (loader), #175 (resolver and bare-name source), #176 (settings and status API), #177 (api-regen), #178 (console).

Acceptance

  • Children closed; README.md has a "Hosts files" section: adding /etc/hosts and a directory, domain expansion and how it differs from the DNS hygiene "local domain" (#138), the bare-name order, reload behaviour, precedence against zones and rewrites, and the Windows path (C:\Windows\System32\drivers\etc\hosts).

Source

audit-feature-parity.md §2A #15; DEDUPE.md §2 and P6.
Owner decision 2026-10-31: "configure it like dnsmasq with multiple hosts file support" = a configurable list of hosts-file paths, read on start and reloaded on change, answering A/AAAA and PTR, optional domain expansion for bare names; it replaces the import-to-rewrites design (Q-PN-11).
Owner decisions 2026-10-31, round 2: bare-name order DHCP names, hosts files, local domain, NXDOMAIN (R2-BARE); empty list by default, 60 s TTL (R2-HOSTS-DEF); hosts files stay in this milestone (R2-MS-HOSTS).

- **Draft:** PN-29 - **Priority:** medium (the main migration path from hosts-file based setups) - **Agent:** none (epic) - **Depends on:** none - **Decisions:** Q-PN-11, R2-BARE, R2-HOSTS-DEF, R2-MS-HOSTS ### Why Nothing reads a hosts file for resolution. `DnsFilterListParser` (`src/dotnet/src/Ninlil.Dns.Server.Filtering/DnsFilterListParser.cs:88-226`) reads the hosts format only to build block lists. The owner wants a list of hosts files that Ninlil answers from directly, the way a common lightweight DNS forwarder's "additional hosts" option works. The behaviour below comes from that tool's public manual page only, never its source, and the tool is not named in code, docs or commits. ### What changes The design, so every child agrees: - **Setting.** `HostsFilesOptions` (section `DnsServer:HostsFiles`): - `Paths`: a list of absolute paths, empty by default (R2-HOSTS-DEF). A path to a directory means every regular file directly in it, read in name order (not recursive). - `ExpandDomain`: a domain, or empty for off. When set, a bare name (no dot) in a file also answers as `<name>.<ExpandDomain>`. - `TimeToLiveSeconds`: default 60 (R2-HOSTS-DEF). - `PollInterval`: default 30 seconds. - Empty `Paths` means a new install answers nothing from `/etc/hosts` until the operator adds it. Ninlil's own host file would otherwise publish `localhost` and the machine's private names to the LAN. The README shows how to add `/etc/hosts`. - `Paths` is a list, so it has no environment variable (AGENTS.md "Configuration"); the other three have. - **Loading.** Every file is parsed in the hosts(5) layout (address, canonical name, aliases, `#` comments). The result is one immutable table swapped in atomically, so a query never sees a half-loaded table. - A file that cannot be read keeps its last good entries and reports an error in the status. - Size and entry caps protect memory. - Reload on change uses a file-system watcher plus a size-and-modification-time poll every `PollInterval`. Technical call: watchers miss events on network file systems and some bind mounts, so the poll is the guarantee and the watcher only makes it faster. - **Answering multi-label names.** A new `IDnsQueryResolver`, registered after the authoritative resolvers and before forwarding (`Program.cs:496-503`): - A and AAAA answers for every address a name has, across all files (the `<name>.<ExpandDomain>` forms included). - PTR for `in-addr.arpa` and `ip6.arpa` (RFC 1035 §3.5, RFC 3596 §2.5) answers the first name listed for that address, in path-list order; with `ExpandDomain` set, a bare name answers as its expanded form. - An A or AAAA question for a hosts name that has no address of that family gets NODATA (RFC 2308 §2.2), so the local name does not leak upstream. Other types pass to the next resolver, so a hosts entry that overrides a public name does not break its MX or TXT. - Technical call: as a resolver it runs after filtering and rewrites (`DnsQueryProcessingPipeline.cs:56-63`), so block lists and rewrites still apply, and an authoritative zone the operator hosts wins over a hosts file. - **Answering bare (single-label) names (R2-BARE).** The resolver does not answer a single-label query itself. The hosts files are the second source in #136's bare-name chain (`LocalHostNameSourceOrder.HostsFiles`): DHCP-registered names (#137) first, then the hosts files, then the local domain (#138), then NXDOMAIN (or upstream when single-label protection is off). So a DHCP client's registered name wins over a stale hosts entry, as the owner ordered. - **Scope.** Per node: a path names a file on one machine, so the setting is not cluster-synced. No per-client scoping (rewrites already do that). Children: #174 (loader), #175 (resolver and bare-name source), #176 (settings and status API), #177 (api-regen), #178 (console). ### Acceptance - [ ] Children closed; README.md has a "Hosts files" section: adding `/etc/hosts` and a directory, domain expansion and how it differs from the DNS hygiene "local domain" (#138), the bare-name order, reload behaviour, precedence against zones and rewrites, and the Windows path (`C:\Windows\System32\drivers\etc\hosts`). ### Source `audit-feature-parity.md` §2A #15; DEDUPE.md §2 and P6. Owner decision 2026-10-31: "configure it like dnsmasq with multiple hosts file support" = a configurable list of hosts-file paths, read on start and reloaded on change, answering A/AAAA and PTR, optional domain expansion for bare names; it replaces the import-to-rewrites design (Q-PN-11). Owner decisions 2026-10-31, round 2: bare-name order DHCP names, hosts files, local domain, NXDOMAIN (R2-BARE); empty list by default, 60 s TTL (R2-HOSTS-DEF); hosts files stay in this milestone (R2-MS-HOSTS).
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lantea-one/ninlil#173
No description provided.