Skip to content

The dns section ​

Code: modules/dns/dns/src/syntax.rs, crates/native-config/src/dns.rs, crates/native-config/src/entity.rs (the dns step in lower).

DNS is the only section that affects other parts of the configuration: it gives outbounds resolvers, the router — a default resolver, and dns.listen produces inbounds and a routing rule. Here — the mechanism of these links; DNS itself is in the dns module.

The module's declarations ​

rust
Provide::Section { key: "dns", kind: None, decode: syntax::section },
Provide::Source  { section: "dns", expand: syntax::listeners },
Provide::Schema  { name: "dns", schema: schema::dns },

requires: ["router", "dial", "tls", "cache"]: the form of DNS rules' match is read by the router — see rules.

Decoding the section ​

syntax::section translates the native form into sing-box's DNSOptions:

  • upstreams — a map by name → servers with tag; servers in native form is an error;
  • bootstrap (per upstream or shared) → the server's domain_resolver; the bootstrap's target must be given as an IP address or be local; an upstream with a host name and no bootstrap is an error;
  • fakeip → a server of type fakeip with the tag fakeip (or a free one);
  • rules — DNS rules (with fuse_options, as for the route), positions — in Decoded::written; response conditions (match_response, response_*) in match are an error: without evaluate, which YAML does not have, they would never match;
  • sing-box cache fields at the section level (cache_capacity, disable_cache, disable_expire, optimistic, independent_cache) are an error pointing to cache.*;
  • listen — checked (a port is needed), but read by the source, not by the section.

Filter parameters: the dns_filter point ​

The dns module opens the dns_filter point; a filter module adds a key to it (adblock — skip_adblock). syntax::skip_filter removes such keys from an upstream and from a rule's to (before config::single, so to: {upstream: x, skip_adblock: true} is allowed), the value is only true/false. The marked upstreams (by name) and rules (by index) are stored in DNSOptions::skip_filter — a field outside the sing-box form (#[config(skip)]); they enter the fingerprint through the dns part (components adds them to cold), so changing them rebuilds the DNS router but not the servers. The schema lists the point's keys on upstreams and in to. Without a filter module the key is an unknown field.

Outbound resolvers: gives ​

Leading rules of the form

yaml
- match: {outbound: proxy}     # one outbound name or "*"
  to: {upstream: bootstrap-dns}

(resolver_prefix) are not query rules but a choice of which upstream an outbound uses to resolve its server's name. The module takes them off the beginning of the list (up to the first rule of another form, a repeated outbound or *) and gives them out as Given:

GivenRecipientHow the loader applies it
{section: "outbounds", name: x, block: "domain_resolver"}outbound xContext::add_block — the entity's domain_resolver block
{section: "route", name: "", block: "default_domain_resolver"} (*)the other outboundsthe route.default_domain_resolver member when the kernel decodes route

The value is DomainResolveOptions (server + options from do: options). The block is not written by hand: route.default_domain_resolver in the text is an error with a hint, and the dial schema has no domain_resolver field. The consumer sees the link as an ordinary block: ours_config::dial::options assembles DialerOptions from the dial block and the domain_resolver block.

The dial block decoder (modules/system/dial/src/block.rs) rejects domain_resolver and domain_strategy written by hand, pointing to dns.rules with an outbound condition, and the sing-box names bind_interface/routing_mark — with a hint at the native name.

Listeners: Source ​

syntax::listeners (Expand) gives, for every dns.listen address:

  • Entity { section: "inbounds", name: unique("inbounds", "dns"), node: {direct: {listen: host:port}} } (default port 53);
  • one Entity { section: "route.rules", node: {match: {inbound: [dns, ...]}, to: hijack-dns} }.

The loader decodes the inbounds as written ones (inbound), marks them supplied = "dns" (visible to checks through Seen::supplied), and puts the rule first in route.rules — before any written rule. Their Origin is dns.listen.

Parts for reload ​

components(dns): every server is a Part { kind: "dns-server", name: tag }; the rest is Part { kind: "dns" } (the DNS router without the servers). If final is not set, the router refers to the first server. A local server with neighbor_domain adds reads: [("route", "dhcp_lease_files")] — changing this route field rebuilds the server.

Positions (dns::origins): a server — dns.upstreams.<name> or dns.fakeip; a rule — dns.rules[i] with the number of elements; dns.final.

Checks from outside ​

The tproxy module (Provide::Check) checks the addresses of inbounds with supplied == "dns" for auto_nft.dns — an example of a check that sees another module's entities only through View.

GPL-3.0-or-later