Server Configuration¶
The [server] section controls ports, bind address, API authentication, and encrypted DNS listeners.
Basic Options¶
[server]
dns_port = 53
web_port = 8080
bind_address = "auto"
metrics_enabled = false
trusted_proxies = ["127.0.0.0/8", "::1/128"]
| Option | Default | Description |
|---|---|---|
dns_port | 53 | UDP and TCP port for DNS queries |
web_port | 8080 | HTTP/HTTPS port for the dashboard and REST API |
bind_address | auto | Default address every listener binds to. auto serves IPv4 and IPv6 on every interface (see Dual-stack), or IPv4 only on a kernel without IPv6; 0.0.0.0 serves IPv4 only, and a specific IP restricts access to it. Must be auto or an IP literal; a hostname is rejected at startup |
web_bind_address | (unset) | Address the dashboard and REST API bind to instead of bind_address. See Dashboard on its own address |
metrics_enabled | false | Serve an unauthenticated Prometheus text-exposition endpoint at /metrics on the web port (opt-in) |
trusted_proxies | ["127.0.0.0/8", "::1/128"] | CIDRs (or single addresses) of reverse proxies whose X-Forwarded-For / X-Real-IP headers are believed on DoH requests and for the address a dashboard login records. See DoH client identity |
Dual-stack (IPv4 + IPv6)¶
bind_address = "auto", the default, makes every listener — Do53 (UDP and TCP), DoT, DoH, DoQ, and the web dashboard — serve IPv4 and IPv6 clients on a single dual-stack socket, unless it has a bind address of its own. A config file without the key, or no config file at all, gets the same:
"auto" binds [::], as "[::]" and a bare "::" do; only "auto" falls back to 0.0.0.0 on a kernel without IPv6. Every listener opens [::] with IPV6_V6ONLY off, so IPv4 is served whatever the host's net.ipv6.bindv6only says. The config file, backups and GET /ferrous/api/v1/config keep saying auto.
bind_address = "0.0.0.0" serves IPv4 only, as it always has. A config that names it, such as the ferrous-dns.toml that older releases shipped and that every existing Docker volume holds, keeps listening on IPv4 until that line is changed to "auto".
IPv4 clients arrive on the dual-stack socket in v4-mapped form (::ffff:192.168.1.10). Do53, DoT, DoQ and the web server normalise them back to plain IPv4 before anything client-facing sees them, so client groups, per-client rules, the per-IP connection limit, the query log and the Pi-hole compatible API's sessions and /api/info/client key a device the same way whichever protocol it used. The same normalisation is applied to the address a PROXY protocol v2 header carries.
DoH is keyed by the socket peer too (canonicalised the same way), except when that peer is one of trusted_proxies — see DoH client identity.
Upgrading from a release that stored mapped addresses
Earlier releases stored the v4-mapped form for DoT and DoQ clients, so a device could end up with two client rows. A migration runs once on first start and rewrites them: ::ffff:10.0.0.1 becomes 10.0.0.1, a mapped row is merged into its plain twin (query counts add up, and a group assigned to the mapped row is kept unless the plain row already had one), the query log follows, and a subnet written as ::ffff:10.0.0.0/104 becomes 10.0.0.0/8. Nothing needs to be done by hand.
Kernels without IPv6¶
Every listener opens a socket in the family of its address: AF_INET for an IPv4 address, which needs no IPv6 in the kernel, and a dual-stack AF_INET6 socket for an IPv6 one. On a kernel booted with ipv6.disable=1 or built without CONFIG_IPV6:
bind_address = "auto"listens on0.0.0.0, IPv4 only, and logsIPv6 is not available in this kernel: bind_address "auto" listens on IPv4 only (0.0.0.0)at startup. The config file, backups andGET /ferrous/api/v1/configstill sayauto, so the same file serves both families again on a kernel with IPv6.- An IPv4 address,
"0.0.0.0"included, binds as it does anywhere else. - An explicit IPv6 address, such as
"[::]"inbind_address,web_bind_addressor a per-listener bind address, is not changed. Its listener fails to start with an error that names the address and says the kernel has no IPv6. A web listener that cannot bind stops the server. A Do53 listener that cannot bind leaves the dashboard up with/healthat 503; a DoT, DoQ or dedicated DoH listener only logs its error, and/healthstays at 200.
IPv6 turned off on the network, or with net.ipv6.conf.all.disable_ipv6 = 1, is not this case: the kernel can still create IPv6 sockets, so "auto" stays dual-stack and serves IPv4 clients as usual.
Per-listener bind addresses¶
Each encrypted-DNS listener can override bind_address, which is useful when the protocols should not all be exposed on the same interface:
[server]
bind_address = "0.0.0.0" # Do53 and the dashboard stay on IPv4
[server.encrypted_dns]
dot_enabled = true
dot_bind_address = "[::]" # DoT is dual-stack
doq_enabled = true
doq_bind_address = "192.168.1.10" # DoQ only on the LAN address
Like bind_address, each override must be an IP literal. A hostname on a listener that is running (for DoH: doh_enabled with a doh_port) stops startup; on one that is off it is ignored with a warning in the log.
See Encrypted DNS for the full list of options.
Dashboard on its own address¶
web_bind_address moves the dashboard and the REST API, over HTTP or HTTPS, off bind_address, while every DNS listener stays where it is. The usual case is a reverse proxy on the same host, or in Docker with host networking: DNS serves the network, and the web server listens on loopback only. In a container on a bridge network, loopback is the container's own, so a proxy in another container cannot reach it there: leave the key unset.
[server]
bind_address = "auto" # DNS for the network
web_bind_address = "127.0.0.1" # dashboard and API for the local reverse proxy only
Unset, the web server binds bind_address, as before. Unlike bind_address, it must be an IP literal: auto is not accepted here.
Everything served on web_port moves with it: the Pi-hole compatible API, /metrics, and DoH when it has no doh_port of its own. A Prometheus on another host then has to scrape through the proxy. --bind (FERROUS_BIND_ADDRESS in Docker) changes bind_address only. --healthcheck probes the web server at web_bind_address.
DoH client identity¶
A DoH query to /dns-query is attributed to the address of the TCP connection it arrived on, and that address picks the client's group and per-client rules (unless the client queries /dns-query/<ClientID>, described below). When the connection comes from a reverse proxy listed in trusted_proxies, the proxy may name the real client instead:
X-Forwarded-Foris read right to left — every proxy appends the address it received the request from — and the first hop that is not itself a trusted proxy is the client. Hops further left were written by the client and are ignored.- Without
X-Forwarded-For, the trusted proxy'sX-Real-IPis used. - On
/dns-query(without a<ClientID>), a request from any other peer is attributed to that peer, whatever headers it carries, so a client cannot spoof another device's IP address through forwarding headers.
The default trusts only loopback, which fits a reverse proxy on the same host. List the proxy's address when it runs elsewhere — for a Docker bridge network that is the proxy container's address or the bridge subnet:
Setting the list replaces the default, so keep the loopback entries if the proxy can also connect locally. Trust only addresses you control: any peer inside the list can claim to be any client.
The same walk names the address a dashboard login records in the session list. The login lockout ignores it and always counts the TCP peer; see Login lockout.
To identify roaming or NATed DoH devices independently of their IP address, clients can also query /dns-query/<ClientID> using an identifier registered on the DoH IDs page (/doh-ids.html). Group resolution evaluates the DoH Client ID first, then falls back to client_ip → subnet → Protected. By default (doh_allow_unregistered_ids = false), unknown Client IDs are rejected with 400 Bad Request; setting doh_allow_unregistered_ids = true in [server.encrypted_dns] (or toggling Allow Unregistered Client IDs on the DoH IDs page) accepts valid unregistered IDs for Query Log attribution while applying the client IP's group rules. Because a registered /dns-query/<ClientID> URL acts as a bearer credential that selects its group's policy regardless of source IP, anyone who knows the URL gets that group's rules — prefer the generated random UUID v4 for groups with lighter filtering. See DoH IDs.
Authentication¶
Ferrous DNS supports session-based authentication and API tokens to protect the dashboard and REST API.
Enabling Authentication¶
[auth]
enabled = true # Enable authentication globally
session_ttl_hours = 24 # Session lifetime without "Remember Me"
remember_me_days = 30 # Session lifetime with "Remember Me"
login_rate_limit_attempts = 5 # Max failed attempts before lockout
login_rate_limit_window_secs = 900 # Lockout window (15 min)
[auth.admin]
username = "admin" # Admin username
password_hash = "" # Argon2id hash (set via setup wizard; empty triggers it)
| Option | Type | Default | Description |
|---|---|---|---|
enabled | bool | true | Enable or disable authentication globally |
session_ttl_hours | int | 24 | Default session lifetime in hours |
remember_me_days | int | 30 | Extended session lifetime with "Remember Me" |
login_rate_limit_attempts | int | 5 | Max failed login attempts before lockout |
login_rate_limit_window_secs | int | 900 | Lockout window duration in seconds |
username | str | admin | Admin username |
password_hash | str | "" | Argon2id password hash |
First-Run Setup¶
When password_hash is empty, Ferrous DNS shows a setup wizard on the dashboard. Set the admin password via the web UI — the Argon2id hash is written to the config file automatically.
Session Authentication¶
Users log in with username and password. A ferrous_session cookie is set on success. The "Remember Me" option extends the session from session_ttl_hours to remember_me_days.
API Token Authentication¶
API tokens provide programmatic access via the X-Api-Key header. Tokens are managed through the REST API or the dashboard under Settings > Security. See API Tokens for endpoint details.
Auth Guard¶
All API endpoints are protected except public auth routes (/ferrous/api/v1/auth/status, /ferrous/api/v1/auth/setup, /ferrous/api/v1/auth/login, /ferrous/api/v1/auth/logout, and the second-factor and passkey login steps) and the health check (/ferrous/api/v1/health).
Outside the API, the dashboard's static files, /ferrous-config.js, each API's /openapi.json and /docs, /metrics when it is on, and DoH need no login either. See Auth Guard.
Background cleanup
A background task runs periodically to prune expired sessions from the database.
CORS¶
The default, ["*"], lets any origin call the API, but without credentials: a browser on another site never sends the session cookie, so it can read only the responses that need no login (/auth/status, /health, /openapi.json). To allow only some origins, list them:
The dashboard itself is same-origin and needs no entry. A list allows no credentials either, and a listed origin may send only the Content-Type and Authorization headers, so a script there cannot send X-Api-Key and reaches only the endpoints that need no login. An integration calls the API from a server, where CORS does not apply.
Security headers¶
Every response of the dashboard's router carries these: the UI, both APIs, /docs, /metrics and DoH on web_port.
| Header | Value | Effect |
|---|---|---|
Content-Security-Policy | frame-ancestors 'self' | Only a page of the same origin may show the dashboard in a frame |
X-Frame-Options | SAMEORIGIN | The same, for browsers that predate frame-ancestors |
X-Content-Type-Options | nosniff | The browser uses each response's declared type instead of guessing one |
Referrer-Policy | same-origin | The dashboard's URLs are not sent to other sites |
Two responses carry none, since neither serves a page: the redirect from plain HTTP to HTTPS when web TLS is on, and DoH on its own doh_port.
A page on another origin, another subdomain or port included, can no longer frame the dashboard. A dashboard app that embedded it from its own host name shows an empty frame instead; open it in its own tab, or serve both under one origin through a reverse proxy. A proxy should not add X-Frame-Options of its own: two different values make browsers ignore the header.
There is no script Content-Security-Policy: Alpine's standard build evaluates its expressions, which such a policy would have to allow.
HTTPS (Web TLS)¶
Serve the dashboard and REST API over HTTPS. When enabled, the same web_port handles both HTTPS and plain HTTP (with automatic redirect to HTTPS).
[server.web_tls]
enabled = false # Enable HTTPS
tls_cert_path = "/data/cert.pem" # PEM certificate path
tls_key_path = "/data/key.pem" # PEM private key path
| Option | Type | Default | Description |
|---|---|---|---|
enabled | bool | false | Enable HTTPS for the web server |
tls_cert_path | str | /data/cert.pem | Path to the PEM-encoded TLS certificate |
tls_key_path | str | /data/key.pem | Path to the PEM-encoded TLS private key |
Quick setup
You can generate a self-signed certificate directly from the UI under Settings > Security > HTTPS / TLS — no command-line tools needed.
Graceful fallback
If enabled = true but certificate files are missing, the server logs a warning and falls back to plain HTTP.
See HTTPS for Web UI for full details, API endpoints, and UI management.
Pi-hole Compatibility¶
Ferrous DNS can expose the Pi-hole v6 API at /api/*, making it a drop-in replacement for existing integrations (Gravity Sync, third-party dashboards, scripts):
When pihole_compat = true:
- Pi-hole API is served at
/api/* - Ferrous DNS native API stays at
/ferrous/api/v1/*, as in every mode
PROXY Protocol v2¶
Enable real client IP detection when running behind a load balancer (HAProxy, AWS NLB, nginx):
Danger
Only enable this when a trusted load balancer always sits in front. Without a load balancer, all TCP DNS connections will be rejected (the server expects the PROXY Protocol header on every connection).
Encrypted DNS¶
Ferrous DNS can serve DNS-over-TLS (DoT), DNS-over-HTTPS (DoH), and DNS-over-QUIC (DoQ) directly to clients. DoT and DoQ require a TLS certificate and private key in PEM format. DoH is served over plain HTTP for a TLS-terminating reverse proxy (or over [server.web_tls] when co-hosted on web_port), so it needs no certificate here.
[server.encrypted_dns]
dot_enabled = true
dot_port = 853
doh_enabled = true
doh_port = 443 # omit to co-host DoH on web_port
doq_enabled = true
doq_port = 853 # UDP port; no collision with dot_port (TCP)
tls_cert_path = "/data/cert.pem"
tls_key_path = "/data/key.pem"
| Option | Default | Description |
|---|---|---|
dot_enabled | false | Enable DoT listener |
dot_port | 853 | TCP port for DoT (RFC 7858 standard: 853) |
dot_bind_address | — | Address for the DoT listener; inherits [server].bind_address when omitted |
doh_enabled | false | Enable DoH endpoints (/dns-query and /dns-query/<ClientID>) |
doh_port | — | Dedicated plain-HTTP port for DoH (behind a reverse proxy); omit to co-host on web_port |
doh_bind_address | — | Address for the dedicated DoH listener; ignored when doh_port is omitted, since /dns-query then binds wherever the dashboard does (web_bind_address, else bind_address) |
doh_allow_unregistered_ids | false | When false, requests to /dns-query/<ClientID> with an unregistered ID return 400 Bad Request; when true, valid unregistered IDs are accepted for Query Log attribution and fall back to the client IP's group rules |
doq_enabled | false | Enable DoQ listener |
doq_port | 853 | UDP port for DoQ (RFC 9250 standard: 853) |
doq_bind_address | — | Address for the DoQ listener; inherits [server].bind_address when omitted |
tls_cert_path | /data/cert.pem | Path to the DoT/DoQ TLS certificate (PEM) |
tls_key_path | /data/key.pem | Path to the DoT/DoQ TLS private key (PEM) |
Missing certificate
If the certificate files are absent at startup, DoT and DoQ are skipped with a warning. DoH and plain DNS start normally.
Generating a Self-Signed Certificate¶
openssl req -x509 -newkey rsa:4096 -nodes \
-keyout key.pem -out cert.pem \
-days 365 -subj "/CN=ferrous-dns"
For production, use Let's Encrypt or your CA.
Client Configuration (DoT)¶
Configure your devices or router to use DoT:
Client Configuration (DoH)¶
Use the DoH endpoint with any compatible client:
See Encrypted DNS features for more details and client setup examples.