English
dns — DNS
The built-in DNS does two jobs:
- answers clients: queries intercepted by the rule
to: hijack-dns, and queries to its own listenersdns.listen; - resolves names for the proxy itself: the addresses of outbound servers, destination domains for
direct,do: resolvein rules, addresses for probes and downloads.
yaml
outbounds:
direct:
direct:
proxy:
trojan:
server: proxy.example.com:443
password: secret
tls:
sni: proxy.example.com
dns:
upstreams:
router:
udp: 192.168.1.1
remote:
https: 1.1.1.1
via: proxy
rules:
- match:
outbound: "*"
to:
upstream: router
- match:
domain_suffix: lan
to:
upstream: router
final:
upstream: remote
cache:
capacity: 4096
optimistic: true
route:
rules:
- match:
protocol: dns
to: hijack-dns
final:
outbound: proxyThe first rule sets the resolver for outbound servers, see Resolvers for outbounds.
Sections
- Upstreams — whom to ask: UDP, TCP, DoT, DoH, DoQ, DoH3, the system resolver, hosts, mDNS;
viaandbootstrap. - Rules — which upstream answers which query; resolvers for outbounds.
- Fakeip and listeners — the pool of fake addresses and own DNS inbounds
listen.
Section fields
| Field | Meaning |
|---|---|
upstreams | Upstreams by name |
bootstrap | The upstream for the names of the upstreams themselves, see Upstreams |
rules | Rules |
final | upstream: <name> — who answers if no to rule matched. Required if there are upstreams |
fakeip | The fakeip pool |
listen | Addresses of own DNS listeners |
cache | The answer cache, see below |
strategy | Which addresses to return when resolving for the proxy: prefer_ipv4, prefer_ipv6, ipv4_only, ipv6_only |
timeout | The timeout of a query to an upstream; 10s by default |
client_subnet | The EDNS Client Subnet for all queries: 203.0.113.0/24 or an address |
reverse_mapping | Remember which domain gave which address, so that connections to that address get the domain for the route rules |
Cache: cache
| Field | Meaning | Default |
|---|---|---|
capacity | How many answers to keep; never less than 1024 (check warns) | 1024 |
optimistic | Answer with a stale record and refresh it in the background: true or a block {enabled: true, timeout: 1d} (how long a stale record may still be served; 3d by default). Needs the cache: with disabled or disable_expire it is a load error | off |
disabled | Do not cache at all | false |
disable_expire | Ignore the TTL: records live until they are evicted | false |
Each upstream has its own cache: the same domain may have different answers from different upstreams. The sing-box fields at the section level (cache_capacity, disable_cache, disable_expire, optimistic, independent_cache) are an error pointing to the cache field (dns: `cache_capacity` is `cache.capacity` ). Answers can be kept across restarts with cache.store: [dns] (cache).
Without a dns section
Without the section (or without upstreams) all queries — both for the proxy and those intercepted by hijack-dns — are answered by the system resolver, like the local upstream.
Checking
ours explain --dns example.com --type AAAA -c config.yaml shows which DNS rules would match (Command line).