DNS
etemenanki-app has one resolver for the running configuration. When an outbound has to turn a name into an address, for example a freedom outbound dialling example.com, a VLESS client connecting to proxy.example.com or a WireGuard tunnel reaching its endpoint, it asks this resolver. The [dns] table chooses where the resolver gets its answers: the host’s own resolver (the default), a DNS server over plain UDP, DNS over TLS, or DNS over HTTPS. Whatever the backend, a cache sits in front of it. A subscribe file can bring a DNS setup of its own, described under With a subscribe file.
Read this page if you want lookups to go to a specific server, to be encrypted, or to reach a private resolver, or if you need to know why a name resolved the way it did.
Choosing a backend
Section titled “Choosing a backend”| Backend | Transport | Reads /etc/hosts, nsswitch.conf, search domains |
How long an answer is cached | Keys it needs |
|---|---|---|---|---|
system (default) |
The host resolver (getaddrinfo) |
Yes | 60 s | none |
udp |
Plain DNS, UDP | No | The record TTL, clamped to 5 s–3600 s | server |
tls |
DNS over TLS (RFC 7858) | No | The record TTL, clamped to 5 s–3600 s | server, server_name |
https |
DNS over HTTPS (RFC 8484) | No | The record TTL, clamped to 5 s–3600 s | server, url |
system is the default because it is the only backend that honours the host’s own name configuration. Switching to a DNS client changes what some names resolve to: an entry in /etc/hosts or a search domain no longer applies. Pick tls or https when the lookups themselves must not be readable on the network, and udp when you want a particular server and privacy does not matter.
A minimal example
Section titled “A minimal example”This configuration runs a local SOCKS proxy that dials destinations directly and resolves every name over DNS over HTTPS:
# A local SOCKS proxy that sends traffic straight out and looks up every# name over DNS over HTTPS instead of the host resolver.
# DNS over HTTPS (RFC 8484). `server` is the address that is dialed and must be# an IP literal with a port; `url` supplies the TLS name, the Host header and# the request path. The certificate is checked against the system CA store.[dns]backend = "https"server = "1.1.1.1:443"url = "https://cloudflare-dns.com/dns-query"
# Accept SOCKS 4/4a/5 clients on the loopback interface only.[[inbound]]tag = "socks-in"protocol = "socks"listen = "127.0.0.1"port = 1080
# Dial the requested destination directly. When the client asks for a name,# freedom resolves it through [dns] above.[[outbound]]tag = "direct"protocol = "freedom"server is the address etemenanki-app connects to. url gives the name the certificate is checked against, the Host header, and the path of the request. The two are separate on purpose: taking the address from the URL would mean resolving the resolver, and there is nothing to resolve it with.
Settings
Section titled “Settings”The [dns] table is optional. Without it, the resolver uses the system backend. The table accepts exactly the keys below; any other key, such as a misspelt backends, is a parse error that names its line.
| Key | Type | Required | Default | Description |
|---|---|---|---|---|
backend | string (enum) | no | "system" | Where answers come from: system (the host resolver, getaddrinfo), udp (plain DNS over UDP), tls (DNS over TLS, RFC 7858) or https (DNS over HTTPS, RFC 8484). Lower case only; any other value fails with dns: unknown backend "…" (expected "system", "udp", "tls" or "https"). |
server | string | depends | — | Required for udp, tls and https (dns: the udp backend needs a server address). The resolver's socket address as an IP literal with a port, such as "192.0.2.53:53" or "[2001:db8::53]:853". A host name or a missing port is refused with dns: invalid server address: invalid socket address syntax, because there is nothing yet to resolve it with. For https this is the address that is dialed; url gives the name and the path. |
server_name | string | depends | — | Required for tls. The name sent as SNI and checked against the resolver's certificate. It is never guessed from server; a missing value fails with dns: the tls backend needs a server name to verify against. The https backend takes its name from url instead. |
url | string | depends | — | Required for https (dns: the https backend needs the resolver's url). Must start with https:// (dns: "…" is not an https:// url). The host is sent as SNI and as the Host header and is what the certificate is checked against, so write it as a name; everything from the first / on is the request path, and /dns-query is used when there is none. A URL with userinfo (user@) or an empty host is refused. |
ca_file | path | no | — | PEM file of extra CA certificates that tls and https trust in addition to the system store, for a resolver with a private certificate. A file with no certificate fails with no certificate in CA PEM bundle. A relative path resolves against the working directory. |
Backend by backend
Section titled “Backend by backend”# Same as leaving [dns] out.[dns]backend = "system"Every lookup goes through getaddrinfo, so the host’s resolver configuration, its timeouts and its retries apply. The host resolver reports no TTL, so each answer is cached for a fixed 60 seconds.
[dns]backend = "udp"server = "192.0.2.53:53"Each query is a single UDP datagram to server, from a new socket of the same address family. Write an IPv6 server as "[2001:db8::53]:53".
[dns]backend = "tls"server = "192.0.2.53:853"server_name = "dns.example.com"server_name is required and is never taken from server: checking a resolver’s certificate against the wrong name is exactly the failure DNS over TLS is meant to prevent.
[dns]backend = "https"server = "192.0.2.53:443"url = "https://dns.example.com/dns-query"The host part of url is the TLS name and the Host header. The path is everything from the first /, or /dns-query if the URL has none. The address and port that are dialled are the ones in server.
A resolver with a private certificate
Section titled “A resolver with a private certificate”If your resolver’s certificate is issued by your own CA, point ca_file at that CA. It is trusted in addition to the system store, not instead of it:
[dns]backend = "tls"server = "192.0.2.53:853"server_name = "dns.example.com"ca_file = "/etc/etemenanki/dns-ca.pem"Use an absolute path. A relative one resolves against the process’s working directory, which is often / under a service manager.
How a lookup works
Section titled “How a lookup works”flowchart TB
Q["Name to resolve"] --> LIT{"IP literal?"}
LIT -- yes --> USE["Use it as is"]
LIT -- no --> HIT{"Fresh entry in the cache?"}
HIT -- yes --> FILTER
HIT -- no --> BACK["Ask the backend"]
BACK --> ANY{"Any address?"}
ANY -- no --> ERR["Lookup fails, nothing cached"]
ANY -- yes --> STORE["Cache with the clamped TTL"]
STORE --> FILTER["Outbound applies its address_family"]
- Address literals skip the resolver. A destination or server written as an IP address is used directly, with no query and no cache entry.
- Names are cached case-insensitively.
Example.COMandexample.comshare one entry. - Only answers with an address are cached. A lookup that failed, or that returned no address, is not stored in the cache, so the next request for that name asks the backend again.
- The cache holds both address families. The outbound that asked then filters and orders the addresses by its
address_familypolicy, described on Outbounds. Outbounds with different policies can share one cache entry. - Concurrent misses are not merged. If several connections ask for the same uncached name at the same moment, each one queries the backend.
| Property | Value |
|---|---|
| Capacity | 8192 names. When it is full, the cache keeps the names that are used most often: a new name may push out an older entry before its TTL ends, or may not be stored at all. |
| Scope | One cache for the whole configuration, shared by every outbound and every balancer probe. (A subscribe file’s DNS setup has two resolvers, each with its own cache.) |
| Lifetime | The cache is kept across reloads as long as [dns] does not change. A reload that changes it builds a new resolver with an empty cache. |
For udp, tls and https, an answer is cached for the smallest TTL among its A and AAAA records, clamped to at least 5 seconds and at most 3600 seconds. The floor stops a zero TTL from defeating the cache; the ceiling stops a very long TTL from pinning a stale address for hours. For system, which reports no TTL, the fixed 60 seconds applies.
Queries
Section titled “Queries”The udp, tls and https backends share one query path:
- A and AAAA are asked in parallel. One failing does not discard the other: a host that has only an A record still resolves when the AAAA query fails. The lookup fails only when neither query produced an address. The IPv4 answers come first in the result, then the IPv6 answers, without duplicates.
- Each query has 5 seconds. The limit covers the whole exchange, including the TCP connect and TLS handshake for
tlsandhttps, and the retry over TCP of a truncatedudpanswer. On expiry the query fails withdns: query timed out. - Each query opens its own connection. Nothing is pooled or kept open between queries, so a lookup that misses the cache costs two connections, one for A and one for AAAA, and for
tlsandhttpstwo TLS handshakes. Once the cache is warm, the resolver is consulted rarely. - The query is a standard recursive question with a random ID. The CNAME chain is left to the server; the resolver reads the A and AAAA records in the answer and skips any other record type. A response with a different ID, or with a non-zero response code such as NXDOMAIN, is an error.
Details that differ per backend:
| Backend | On the wire |
|---|---|
udp |
One datagram to server, answer read into a 512-byte buffer. The query carries no EDNS, so a conforming server keeps its answer within 512 bytes. A server that sets the truncation (TC) flag is asked again over TCP (RFC 7766), in the same 5 seconds. |
tls |
TLS 1.2 or newer, no ALPN, server_name as SNI. The message is sent with a 2-byte length prefix, as in DNS over TCP. |
https |
TLS 1.2 or newer, ALPN http/1.1. An HTTP/1.1 POST to the URL’s path with Content-Type: application/dns-message, Accept: application/dns-message and Connection: close. The response body is everything after the headers, read to the end of the connection; any status other than 200 is an error. |
The DNS over HTTPS client speaks only HTTP/1.1, so the server must accept an HTTP/1.1 request. It also does not decode Transfer-Encoding: chunked: a server that sends a chunked response has the chunk framing read as part of the DNS message, and the query fails.
Who uses the resolver
Section titled “Who uses the resolver”| Where | What is looked up |
|---|---|
freedom outbound, TCP |
The destination name, when the client asked for a name. |
freedom outbound, UDP |
Each destination name a datagram is sent to. |
| SOCKS, HTTP, Shadowsocks, Trojan, VLESS, VMess, AnyTLS and sss outbounds | The outbound’s own server, to connect to the upstream proxy. |
| Hysteria 2 outbound | The outbound’s server, when it opens its QUIC connection. |
| WireGuard outbound | The endpoint, when the tunnel comes up, with endpoint_address_family applied. Destination names inside the tunnel. |
| Balancer health probes | The probed member’s server address. The lookup counts against the probe’s timeout. |
Who does not
Section titled “Who does not”- Destinations sent to an upstream proxy. A SOCKS, HTTP, Shadowsocks, Trojan, VLESS, VMess, AnyTLS, sss or Hysteria 2 outbound passes the destination name to the proxy server unchanged; the server resolves it.
- Routing. The router never resolves a name. IP and GeoIP rules match only when the destination is an IP address. A name found by sniffing is used for matching domain rules and is not looked up either. See Routing.
Reloading
Section titled “Reloading”A reload that leaves [dns] unchanged keeps the resolver and its cache. A change to [dns] builds a new resolver with an empty cache, and the reload summary lists dns under built. Because every outbound except blackhole holds the resolver, the same reload builds a new version of each of them: new connections use the new versions, and balancers start their health checks again. If the new [dns] table is invalid, the reload is refused with reload: <error>; keeping the running config, and the running configuration keeps its resolver and cache. See Hot reload.
With a subscribe file
Section titled “With a subscribe file”A subscribe file with a [dns] table replaces the configuration’s [dns], and a warning says so when the configuration’s table sets anything. Its DNS setup splits resolution in two:
| Resolver | Servers | Looks up |
|---|---|---|
| Direct | pre_proxy, asked from this host, one after another until one answers |
Proxy servers’ names, WireGuard endpoints, balancer probes, and the names of through_proxy servers |
| Proxied | through_proxy, reached through the route table, one after another |
The destinations that freedom and WireGuard tunnels connect to, and applications’ own DNS queries. With through_proxy empty, the direct resolver does this too. |
- The server strings are URLs:
"udp://192.0.2.53:53","tls://203.0.113.53:853#dns.example.com","https://dns.example.com/dns-query", or"system"inpre_proxyonly. The subscribe page lists the forms and their default ports. - A
through_proxyquery travels as a TCP connection to the server’s address, and the route groups decide which outbound carries it. Audp://server is asked over TCP in that case. use_hosts = trueanswers from the system hosts file first, in both resolvers.- Applications’ DNS is answered locally: every connection to port 53, on any inbound, goes to the proxied resolver instead of being routed. AAAA answers are withheld unless
resolve_ipv6 = true. - Two combinations are refused when the resolvers are built:
building dns failed: dns: the system resolver cannot be reached through a proxyfor"system"inthrough_proxy, andbuilding dns failed: dns: server "<name>" is a name, and nothing resolves it; write its addressfor apre_proxyserver written by name.
Errors
Section titled “Errors”When the configuration is checked
Section titled “When the configuration is checked”These appear from --test, at startup, and in the log of a reload that was refused.
| Error | Cause | Fix |
|---|---|---|
TOML parse error at line <n>, column <m>, in [dns] |
A misspelt key in [dns]. |
Use one of the keys in the table above. |
dns: unknown backend "UDP" (expected "system", "udp", "tls" or "https") |
backend is not one of the four values, or is not lower case. |
Write the value in lower case. |
dns: the udp backend needs a server address |
udp, tls or https without server. The message names the backend. |
Add server. |
dns: invalid server address: invalid socket address syntax |
server is a host name, or has no port. |
Write an IP address and a port, such as "192.0.2.53:53". |
dns: the tls backend needs a server name to verify against |
tls without server_name. |
Add the name on the resolver’s certificate. |
dns: the https backend needs the resolver's url |
https without url. |
Add url. |
dns: "…" is not an https:// url |
url does not start with https://. |
Use an https:// URL. |
dns: "…" has no usable host |
url contains userinfo (user@), or has an empty host. |
Remove user@, or add the host. |
… No such file or directory (os error 2) |
ca_file does not exist. |
Check the path; use an absolute one. |
building dns failed: no certificate in CA PEM bundle |
ca_file contains no PEM certificate (tls and https). |
Point it at a PEM file. |
When a lookup fails
Section titled “When a lookup fails”A failed lookup fails the TCP connection that needed it. On a TCP inbound, the error is logged at debug level as the connection ends, for example socks connection from Some(127.0.0.1) ended: dns: query timed out. In a freedom UDP flow, a datagram whose destination does not resolve is dropped, and the drop is logged at debug as freedom: dropping a datagram to an unresolvable …. Set [log].level = "debug" to see these lines.
| Error | Meaning |
|---|---|
failed to lookup address information: Name or service not known |
The system backend could not resolve the name. |
dns: query timed out |
The server did not answer within 5 seconds, or for tls and https, the connection or handshake did not finish in time. |
Connection refused (os error 111) |
Nothing listens on server’s port (udp), or the TCP connection was refused (tls, https). |
dns: server returned rcode 3 |
The server answered with an error code: 3 is NXDOMAIN (no such name), 2 is SERVFAIL. |
dns: example.com did not resolve |
The server answered, but with no A or AAAA record. |
dns: doh server answered "HTTP/1.1 502 Bad Gateway" |
The DNS over HTTPS server replied with a status other than 200. Check the path in url. |
dns: no http header |
The DNS over HTTPS server closed the connection without a complete HTTP response head. |
dns: response id … does not match query … |
The reply is not the answer to this query, for example a chunked DNS over HTTPS body. |
dial: no usable ipv6_only destination address for example.com:443 |
The name resolved, but to no address that the outbound’s address_family allows. See Outbounds. |
An OpenSSL error mentioning certificate verify failed |
The resolver’s certificate does not chain to a trusted CA or does not match server_name or the host in url. Add its CA with ca_file, or correct the name. |