Skip to content

[Host] Local Mappings & Targeted DNS Routing ​

This section configures static domain mappings, domain aliases, and per-domain upstream resolvers with dedicated outbound network paths.

Architecture & Resolution Flow ​

text
Client Initiates DNS Request
           │
           ▼
┌────────────────────────────────────────────────────────────────────────────┐
│ Phase 1: [Host] Local Mapping Match                                        │
│ (Exact domain, wildcards * / ?, or external domain-set)                    │
└────────────────────────────────────┬───────────────────────────────────────┘
                                     │
        ┌──────────────┬─────────────┴─┬──────────────┬──────────────────────┐
        │ (Match)      │ (Match)       │ (Match)      │ (Match)              │ (No Host match)
        ▼              ▼               ▼              ▼                      ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────────────────┐
│ Static IP    │ │ Domain Alias │ │ Targeted DNS │ │ DNS Script   │ │ Phase 2: Fall back to    │
│ Mapping      │ │ (domain:xxx) │ │ Upstream     │ │ (script:xxx) │ │ [General] dns-server     │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │ (adds system if needed)  │
       │                │                │                │         └────────────┬─────────────┘
       ▼                ▼                ▼                ▼                      ▼
 Return preset IP  Recursively      Query specified  Execute JS             Query global
                   resolve target   upstream(s)      script                 dns-server
       │                │                │                │                      │
       └────────────────┴────────────────┴────────────────┴──────────────────────┘
                                           │
                                           ▼
                                   DNS Resolution Done

Domain resolution follows this processing order:

  1. Phase 1: [Host] Prioritized Match DNS queries evaluate first against the [Host] mapping table, which supports exact domains, wildcard patterns (* and ?), and external domain sets (domain-set). When matched, requests are processed by one of four target types:
    • Static IP Mapping: Returns configured IPv4/IPv6 addresses directly without network queries.
    • Domain Alias: Uses domain:target_domain to point queries to a canonical target domain, recursively retrieving and returning the target's resolution.
    • Targeted DNS Upstream Routing: Uses server:upstream_url[#options] to assign one or more dedicated DNS resolvers for specific domains; supports binding to specific proxy outbounds via #outbound or following traffic routing rules via #route.
    • DNS Script: Uses script:name to invoke a type=dns script in Script to dynamically return resolved addresses or upstream servers (cannot be combined with domain-set: rules).
  2. Phase 2: [General] Global dns-server Fallback If the queried domain matches no rules in [Host], resolution falls back to global dns-server in General (automatically supplementing system when empty or lacking a direct plain upstream).
  3. Top-to-Bottom Precedence When multiple entries exist within [Host], they evaluate sequentially from top to bottom, with earlier entries taking precedence.

Syntax Declaration ​

[Host] lines provide four declaration formats depending on the target type:

ini
# 1. Static IP mapping format
pattern = ip_address
pattern = ip_address, ip_address, ...
pattern = [ip_address, ip_address, ...]

# 2. Domain alias format
pattern = domain:target_domain

# 3. Targeted DNS upstream format
pattern = server:upstream_url[#options]
pattern = server:upstream_url[#options], server:upstream_url[#options], ...
pattern = [server:upstream_url[#options], server:upstream_url[#options], ...]

# 4. DNS script format
pattern = script:name

Syntax Elements ​

  • pattern: Domain matching pattern, supporting exact domains, wildcard patterns (*, ?), and external domain sets (domain-set:).
  • ip_address: Valid standard IPv4 or IPv6 address (write IPv6 as fd00::1 in lists, or optionally [fd00::1] as a standalone single value). Multiple IPs support top-level comma-separated lists or [ip1, ip2] bracketed lists.
  • domain:target_domain: Domain alias prefix domain:, followed immediately by the target canonical domain.
  • server:upstream_url: Upstream resolver prefix server:, followed immediately by the upstream DNS resolver address (supporting standard UDP/TCP, DoT, DoQ, and DoH). Multiple upstreams support top-level comma-separated lists (server:upstream1, server:upstream2 or shorthand server:upstream1, upstream2) or [server:upstream1, server:upstream2] bracketed lists.
  • script:name: DNS script prefix script:, followed immediately by a type=dns script name declared in Script.
  • #options: URL fragment parameters appended to the upstream address to control transport policy and outbound network paths.

Parameter Reference ​

Domain Matching Patterns ​

  • Exact Domain (format: example.com) Matches only the exact domain name itself, excluding subdomains.
  • Wildcard Domain (format: *.example.com, api-?.example.com) Supports * (matches zero or more characters) and ? (matches any single character), e.g., matching subdomains or single-character host patterns.
  • External Domain Set (format: domain-set:resource_url) References external domain list resources; the domain-set: prefix must be strictly lowercase (uppercase fails parsing). resource_url can be a local file path or remote HTTP/HTTPS link. Entries starting with . match suffixes; others match exact domains. Shares caching and auto-refresh mechanisms with DOMAIN-SET in Rule; combining domain-set: with a script: target is disallowed.

Upstream Routing Options ​

Control parameters are appended to the upstream URL starting with #. Multiple parameters can be separated using &, ;, or ,. If , is used inside a multi-upstream list (or if an entry contains special delimiters or inline comment triggers), enclose the entire server:... item in double quotes:

  • outbound (Policy name string, unset) Explicitly specifies the proxy server or policy group used to send the DNS request (e.g., #outbound=DIRECT or #outbound=ProxyNode). Connections use the dispatcher's specified outbound mechanism, taking precedence over route and the current proxy mode.

    ini
    *.internal.example = server:10.0.0.53#outbound=InternalProxy
  • route (Boolean or standalone flag, default false) When outbound is unset, setting true (or simply #route) instructs the system to route DNS requests dynamically according to routing rules (Rule).

    ini
    *.wiki.org = server:https://1.1.1.1/dns-query#route

Default Transport Behavior ​

With #route or #outbound, upstream connections pass through the dispatcher and appear in Connection with their destination, effective outbound, routing logs, and traffic counters. Records represent upstream transport connections; cache hits and queries reusing an existing upstream connection do not create additional records.

If neither #outbound nor #route is configured, requests to the upstream are sent via direct physical connections by default. Specifying outbound or route is not supported for the system default resolver (system).

Circular Reference Detection ​

The system detects circular references when loading domain aliases (domain:target_domain). If direct or indirect circular dependencies exist, configuration parsing fails with an error.

Merging Rules ​

[Host] is a named-entry dictionary section keyed by pattern. When used with Plugin, entries with an identical pattern overwrite earlier definitions, and new entries append to the section by default (%APPEND%). You can declare %INSERT% on the section header or first line to prepend new entries to the top of the [Host] list (evaluated with higher priority).

Configuration Examples ​

Basic Configuration ​

ini
[Proxy]
InternalProxy = socks, 10.8.0.1, 1080
GlobalProxy = socks, 198.51.100.1, 1080

[Host]
# 1. Static IP mappings
router.local = 192.168.1.1
dev.internal.net = 10.0.0.10, 10.0.0.11, fd00::1
backup.internal.net = [10.0.0.12, 10.0.0.13]

# 2. Domain alias
stage.example.com = domain:example.com

# 3. Targeted multi-upstream resolvers with designated outbound
*.internal.example = server:10.0.0.53#outbound=InternalProxy, server:10.0.0.54

# 4. Targeted DoH resolver following routing rules
*.wiki.org = server:https://1.1.1.1/dns-query#route

# 5. External domain set with designated outbound
domain-set:./lists/domains.list = server:tls://8.8.8.8#outbound=GlobalProxy

DNS Scripts ​

script:name references a type=dns script in Script; configuration validation fails if the reference is missing, targets another script type, or is used on a domain-set: rule.

ini
[Script]
resolver = type=dns, script-path=./resolver.js

[Host]
*.example.com = script:resolver

The script accesses the domain name via $domain and completes resolution using $done:

javascript
$done({ addresses: ["192.0.2.1", "2001:db8::1"], ttl: 60 });

Four mutually exclusive result formats are supported: address (single IP), addresses (array of IPs), server (single DNS server IP), and servers (array of DNS server IPs). Servers use UDP port 53, reusing existing DNS connectors. IP addresses are filtered by request type, returning empty results if no matching address family exists.

Address results are cached only when a positive integer ttl (seconds) is explicitly specified; they are not cached when unset or set to 0. Once cache expires, the script executes synchronously. Server results isolate upstream caches per server list after each execution; switching servers does not reuse cached results from previous lists. Updating script resources or reloading configuration clears the DNS cache.

$done({}) falls back to standard DNS resolution. Execution failures, unloaded resources, invalid results, or empty address/server arrays log errors or warnings and fall back to standard DNS. Bootstrap DNS lookups and HTTP sub-requests initiated by scripts bypass DNS scripts, preserving static Host mappings, domain aliases, and targeted upstreams.