Configuration reference
Ward reads one YAML file, validates every field at startup, and refuses to run on a bad value. The error names the field and the fix:
config validation error: field "upstreams[0].server_name": must not be empty — remediation: set it to the TLS SNI name of the upstream, e.g. "dns.quad9.net"An unknown key anywhere in the file, at the top level or inside a section, is a config error. When unknown keys are the only problem, the error lists each one with its line, its section and the valid keys. For a misspelled blocklist key and --config ./ward.yaml, Ward prints on stderr:
config errorconfig error in ./ward.yaml: line 10: unknown key "blocklist" at top level (valid keys: listen, log_level, upstreams, blocklists, allowlists, decoys, block_response, timeouts, model)remediation: fix the spelling or remove the key in ward.yaml; see ward.example.yaml for a templateward serve, ward doctor, ward config export and ward eval (when it reads the config, so not with --builtin) refuse the file and exit with code 2.
A later YAML document that has content is also a config error, for example config error in <path>: another document starts at line N. Extra --- separators with nothing after them are ignored.
Where Ward looks
Section titled “Where Ward looks”The first match wins:
--config <path>$XDG_CONFIG_HOME/protocol-ward/ward.yaml(~/.config/protocol-ward/ward.yamlwhenXDG_CONFIG_HOMEis unset)/etc/protocolward/ward.yaml
If you pass --config, Ward uses that path and does not fall back to the others.
Complete example
Section titled “Complete example”listen: "127.0.0.1:5354"log_level: "info"
upstreams: - address: "9.9.9.9:853" server_name: "dns.quad9.net" - address: "1.1.1.1:853" server_name: "one.one.one.one"
blocklists: - id: "trackers" path: "./blocklists/trackers.txt"
allowlists: - id: "my-overrides" path: "./allowlists/overrides.txt"
decoys: - id: "home-decoys" path: "./decoys.txt"
block_response: mode: "address" a: "0.0.0.0" aaaa: "::"
timeouts: dial: "3s" query: "2s" shutdown: "5s"
model: builtin: lexicallisten
Section titled “listen”Required. A string of the form host:port. The port is plain digits from 1 to 65535, with no sign and no leading zeros: +53, 053 and 0080 are rejected, and Ward exits with code 2. ward.yaml never accepts port 0; a kernel-picked DNS port is available only through ward serve --listen-addr. There is no default; the bind address is always your choice. Use 127.0.0.1:5354 to try Ward locally (5353 belongs to mDNS on macOS) and :53 to serve a network, which needs privileges to bind. ward serve --listen-addr overrides it for one run; see DNS address override. The key stays required.
log_level
Section titled “log_level”One of debug, info, warn, error. Default info.
upstreams
Section titled “upstreams”Required, at least one. DNS-over-TLS resolvers that Ward forwards to.
| Key | Type | Notes |
|---|---|---|
address |
host:port |
Required. DoT is usually port 853. |
server_name |
string | Required. The name on the upstream’s TLS certificate (SNI). |
ca_bundle |
path | Optional. A PEM file of CA certificates that pins trust for this upstream. Omit it to use system roots. Ward reads and checks the file at startup. |
blocklists
Section titled “blocklists”Optional. Omit the key to run Ward as a plain forwarder. If the key is present it must have at least one entry.
| Key | Type | Notes |
|---|---|---|
id |
string | Required and unique. Appears in every block log line. |
path |
path | Required. A local file of hosts-file lines (0.0.0.0, 127.0.0.1 or AdAway 0 prefix) or AdGuard ||host^ rules. Plain one-name-per-line files are not accepted. Names must follow the hostname rule, and skipped lines are counted at load. Relative paths resolve against the directory you run ward from. |
allowlists
Section titled “allowlists”Optional, with the same shape and rules as blocklists. An allowlist hit beats a blocklist hit.
decoys
Section titled “decoys”Optional, with the same keys as blocklists (id and path). Files hold hosts-file lines or plain hostnames, and each entry matches that exact name only, not names beneath it. Decoys are checked before everything else, are never forwarded, and are never included in ward config export. See Decoys. See the hostname rule for how lines are read and reported.
Hostname rule
Section titled “Hostname rule”Ward applies one rule to every name in a block, allow or decoy file. It checks list entries only. ward serve does not check queries against it. It lowercases a query, strips one trailing dot and looks it up, so a query that breaks the rule can still match a listed name above it. With ads.example.com blocked, a query for -x.ads.example.com is blocked too. Decoys match exactly, so an invalid query misses.
A name is valid when:
- After Ward trims surrounding whitespace, lowercases the name and strips one trailing dot, it is not empty and is at most 253 bytes. Two trailing dots are invalid.
- Every byte of the trimmed name is ASCII. Lookalike characters such as U+212A (the Kelvin sign) are rejected, not folded to
k. - Each label between dots is 1 to 63 bytes of
a-z,0-9,-and_. A label cannot start or end with a hyphen.
Underscores are allowed, so _dmarc.example.com and _ldap._tcp.example.com load.
Block and allow files
Section titled “Block and allow files”Lines are 0.0.0.0 host, 127.0.0.1 host, 0 host or ||host^. Comment lines that start with # and blank lines are skipped and not counted. Inline comments are not accepted: a line that has one is skipped. Ward also skips the system aliases localhost, localhost.localdomain and broadcasthost.
Every skipped line that has content is counted in skipped_lines on the hostlist: loaded source log line for that source. This covers lines of the wrong shape, invalid names and the system aliases. The system aliases are counted and logged like any other skipped line. Duplicate names within a source are merged and not counted. Ward logs the first 16 per source at WARN. The hostlist: skipped unparsable line entry carries source_id, path, line, content and reason. content is the line as read from the file. A line longer than 64 bytes is cut to at most 64 bytes (on a character boundary) and marked with .... A hostname or leading field that reason quotes is cut the same way.
Decoy files
Section titled “Decoy files”A line is one plain hostname, or <ip> <hostname>. Ward uses the second field as the name and does not validate the first. Inline # comments are stripped. Decoys do not exclude the system aliases.
skipped_lines on the decoy: loaded source log line counts the lines that have content but that Ward cannot load: lines with three or more fields, and lines whose name breaks the rule. Comment lines and blank lines are not counted. Duplicate names, within a file or from an earlier decoy file, are merged and not counted. Ward logs the first 16 skipped lines per source at WARN. The decoy: skipped invalid hostname entry carries source_id, path, line and reason. It has no content field. A line with three or more fields is logged under the same message, and its reason gives the field count, such as expected "<hostname>" or "<ip> <hostname>" (got 3 fields). For a name that breaks the rule, the reason quotes the rejected name, and a name longer than 64 bytes is cut to at most 64 bytes (on a character boundary) and marked with ....
Load errors
Section titled “Load errors”A block, allow or decoy file that loads no names, for example one where every line is invalid, is an error. ward serve refuses to start and exits with code 1. The error names the source. ward doctor does not read list files, so it does not catch this.
The line limit is 1 MiB (1,048,576 bytes) in block, allow and decoy files, and it counts the line ending: a line of 1,048,575 bytes followed by \n is read like any other line, and one byte more is not. A last line with no line ending has the same limit. With \r\n line endings, the longest line is one byte shorter. A line over the limit is not skipped. It stops ward serve at startup with exit code 1, and the error names the line. For an overlong third line in ./decoys.txt, Ward prints on stderr:
decoy errordecoy load failed: decoy: "./decoys.txt" line 3 reaches the 1 MiB line limit (the limit counts the line ending): bufio.Scanner: token too longremediation: split or remove line 3; each line holds one hostname (at most 253 bytes) (secondary: check decoys[*].path values in ward.yaml)A block or allow file fails the same way, under the label blocklist error or allowlist error. A list or decoy load error names its own fix first on the remediation: line; the hint to check the path values in ward.yaml follows as (secondary: …).
block_response
Section titled “block_response”Optional. Shapes the answer to a blocked query.
| Key | Default | Notes |
|---|---|---|
mode |
address |
address or nxdomain. |
a |
0.0.0.0 |
IPv4 returned for A queries in address mode. Must be omitted in nxdomain mode. |
aaaa |
:: |
IPv6 returned for AAAA queries in address mode. Must be a real IPv6 address, not IPv4-mapped. Must be omitted in nxdomain mode. |
In address mode, query types other than A and AAAA get NXDOMAIN. In nxdomain mode every type does.
timeouts
Section titled “timeouts”Durations in Go syntax (500ms, 3s). Every value must be greater than zero.
| Key | Default | Meaning |
|---|---|---|
dial |
3s |
TCP connect plus TLS handshake to an upstream. Capped by the attempt’s share of query. |
query |
2s |
End-to-end budget for one forwarded query, failover included. |
shutdown |
5s |
How long Ward drains in-flight queries on SIGTERM. |
Each query has one query budget. At most two upstreams are tried per query: the round-robin pick, then the next one. With one upstream, the attempt gets all of it. With two or more, the first attempt is capped at half and the fallback gets the rest, so a hung primary costs about query/2 before the fallback answers. With three or more upstreams, not every upstream is tried for a given query.
Ward does not track upstream health, so a hung primary costs about query/2 each time round robin picks it. Failover happens on an error or timeout only. An answer from the upstream, including SERVFAIL or REFUSED, is returned as is. When both tried upstreams fail, Ward answers SERVFAIL within query.
With the default query of 2s and two or more upstreams, an upstream with a round-trip time above about 250 ms can miss the 1 s first-attempt share on a cold connection, because TCP, TLS and the query take 3 to 4 round trips. Raise query on such links.
Optional. Omit it to run without a behavioral detector. When model is present, set exactly one of builtin or command.
| Key | Type | Notes |
|---|---|---|
builtin |
string | lexical runs Ward’s built-in hostname detector in-process. See Behavioral detector. |
command |
list of strings | argv for an external classifier that Ward runs as a separate sibling process and talks to over newline-delimited JSON on stdio. |
env |
list of KEY=value |
Environment for command only; setting it together with builtin is a validation error. Omit it to inherit Ward’s environment; [] starts the classifier with an empty one. |
Verdicts from either kind are recorded as flags and are never enforced in the beta.
Not in the file
Section titled “Not in the file”- DNS address override.
ward serve --listen-addr <host:port>replaceslistenfor that run. It applies toward serveonly.ward.yamlmust still contain a validlisten, because Ward validates the file before it applies the flag.ward doctorhas no--listen-addrflag and checks thelistenin the file. The flag follows the same port rule aslisten, but it also accepts port 0, and then the kernel picks a free port. Ward logs JSON. With port 0, once the DNS port is bound, Ward logs aWARNline,ward serve: --listen-addr port 0; the kernel picks the DNS port. Itsaddrfield is the bound address, which changes on every start: point clients at it, or pass a fixed port for production. This line is not logged if startup fails before the DNS port is bound, or iflog_leveliserror.GET /healthzreports the bound address asdns_addrat everylog_level; see the Health endpoint entry under Not in the file. A malformed value is a config error: Ward exits with code 2 before it binds anything. If the bind fails, the error tells you to change--listen-addrinstead ofward.yaml. - Dashboard address. The dashboard serves on
127.0.0.1:18987. Override it withward serve --dash-listen-addr. The host must be127.0.0.1,::1(written[::1]:18987) orlocalhost(in any letter case), because the dashboard shows your DNS activity. The port follows the same rule aslisten, but port 0 is also accepted: for example,--dash-listen-addr 127.0.0.1:0asks the kernel for a free port. A malformed value, including an empty port like127.0.0.1:or a service name like127.0.0.1:http, is aconfig errorand Ward exits with code 2. Any other host, including other loopback addresses such as127.0.0.2, is adashboard errorand Ward exits with code 1. Both are reported before Ward builds its upstreams or loads the block, allow and decoy lists, and before anything binds; a brokenward.yamlor--listen-addris still reported first. The bound address is thelistenfield of thedashboard: readylog line. - Health endpoint.
ward serveservesGET /healthzon the dashboard address. It returns JSON with these fields:status: staysokwhatever the other fields say.uptime_seconds: seconds sinceward servestarted.last_decision:nulluntil the first decision. After that it holdsqname,action,matched_label(omitted when empty) andat.classify_dropped: a running count, sinceward servestarted, of classifications Ward dropped because the slow path was full or the classifier was still busy when the classify timeout ended. OS connectivity probes and names the detector cannot score are not counted, although Ward logs them aspolicy: classify skipped. It is a counter, not a health signal.classifier:nonewhen there is nomodel, otherwiseokorunavailable.unavailablemeans themodel.commandprocess failed to start or stopped working (it exited, the pipe broke, it sent a malformed reply, or it gave no reply within 4 s). It staysunavailableuntilward serverestarts.builtin: lexicalreportsok.dns_addr: the address the DNS listeners bound, ashost:port. It is""until the DNS listeners are ready, then the bound address, the kernel-picked port included when--listen-addruses port 0. It is never cleared and is reported at everylog_level. Likeclassify_dropped, it is not a health signal: a non-empty value does not show the listeners are serving now.
Commands
Section titled “Commands”| Command | What it does |
|---|---|
ward serve |
Run the resolver and dashboard. Flags: --listen-addr, --dash-listen-addr (see Not in the file). |
ward doctor |
Validate the config, check that the bind address is free, and check TCP reachability of each upstream. |
ward config export |
Print the validated config as YAML, with decoys left out. The model stanza is not exported either, so re-add it if you restore from an export. ca_bundle paths are printed as written. |
ward update verify <dir> |
Verify a signed update bundle on disk. No network access. |
ward eval |
Score a labelled hostname suite against the configured classifier and report accuracy. |
ward version |
Print the version. |
Every command that reads config accepts --config <path>.