Skip to content
Edit this page

DNS Configuration

ClashRS includes an anti-spoofing DNS resolver and a multi-protocol local DNS server supporting UDP, TCP, DoT, DoH, and DoH3.

When dns.enable is false (default), ClashRS delegates name resolution to the operating system (SystemResolver) and starts no local DNS server.

All dns Fields

Key Type Default Description
enable bool false Enable the built-in DNS resolver and optional local DNS server.
ipv6 bool false Resolve AAAA records. Effective value is config.ipv6 && dns.ipv6 (both must be true).
use-hosts bool true Look up top-level hosts entries before querying upstreams (localhost -> 127.0.0.1 is always present).
listen string or object None Local DNS server bind address(es). Omit to disable the local DNS listener. See DNS Listeners.
enhanced-mode normal | fake-ip | redir-host normal fake-ip allocates synthetic IPs from fake-ip-range. redir-host is accepted for parsing only and is a no-op (logs a warning).
fake-ip-range CIDR string "198.18.0.1/16" Address pool used in fake-ip mode. Validated even when dns.enable: false.
fake-ip-filter list[string] [] Domains that bypass Fake-IP and return real IPs (supports StringTrie patterns such as *.lan, +.example.com). Outbound proxy server hostnames are automatically excluded to prevent loops.
default-nameserver list[string] ["114.114.114.114", "8.8.8.8"] Bootstrap DNS servers used to resolve hostnames of DoH/DoT upstreams and proxy-server-nameserver. Must be non-empty and contain IP addresses only (no hostnames). Unaffected by respect-rules.
nameserver list[string] [] Primary upstream DNS servers. Must be non-empty when dns.enable: true, except when Mihomo-style TUN is active (in which case empty nameserver falls back to default-nameserver).
fallback list[string] [] Secondary upstream DNS servers used according to fallback-filter.
fallback-filter object See below Rules deciding when to prefer fallback results over nameserver.
proxy-server-nameserver list[string] [] Dedicated upstreams for resolving outbound proxy server hostnames (domain-based DoH/DoT URLs are allowed and bootstrapped via default-nameserver). Unaffected by respect-rules.
nameserver-policy map[domain -> string] {} Per-domain upstream override. Each value is a single upstream string (not a list).
edns-client-subnet object None Attach ECS to upstream queries (ipv4 and/or ipv6 CIDR; at least one must be set). Does not overwrite an existing ECS option on incoming requests.
respect-rules bool false Route nameserver, fallback, and nameserver-policy upstream traffic through the rule engine instead of DIRECT.

Unsupported Mihomo DNS Keys

use-system-hosts, cache-algorithm, fake-ip-filter-mode, and direct-nameserver are not implemented in ClashRS. Response caching uses a fixed 1,024-entry LRU cache (and a 1,024-entry, 3-second reverse IP→domain cache).

Local DNS Listeners (dns.listen)

dns.listen supports two forms:

dns:
  enable: true
  listen: 127.0.0.1:5353

A leading colon such as :5353 expands to 0.0.0.0:5353.

Expose UDP, TCP, DoT, DoH, and DoH3 simultaneously:

dns:
  enable: true
  listen:
    udp: 127.0.0.1:5353
    tcp: 127.0.0.1:5353
    dot:
      addr: 127.0.0.1:853
      ca-cert: certs/dns.crt
      ca-key: certs/dns.key
    doh:
      addr: 127.0.0.1:8443
      ca-cert: certs/dns.crt
      ca-key: certs/dns.key
      hostname: dns.example.com
    doh3:
      addr: 127.0.0.1:8443
      ca-cert: certs/dns.crt
      ca-key: certs/dns.key
      hostname: dns.example.com
  • dot: addr (required), optional ca-cert, ca-key.
  • doh & doh3: addr (required), optional ca-cert, ca-key, hostname (TLS / QUIC SNI).

Upstream URL Syntax

Scheme Default Port Example
udp:// (or omitted) 53 1.1.1.1, udp://8.8.8.8:53, 2400:3200::1
tcp:// 53 tcp://8.8.8.8:53
tls:// (DoT) 853 tls://dns.quad9.net:853
https:// (DoH) 443 https://cloudflare-dns.com/dns-query
dhcp:// — dhcp://eth0 (queries DNS from the interface's DHCP lease)

Important details verified from source:

  • "system" is not supported as an upstream entry (logged and skipped).
  • DoH path is fixed to /dns-query; custom URL paths on https:// upstreams are ignored. Connecting to an IP-literal DoH server disables hostname certificate verification.
  • URL fragment routing modifiers (separated by & after #):
  • #<proxy_name> or #proxy=<proxy_name> — send DNS queries through a specific outbound proxy or group.
  • #interface=<iface|auto> — bind upstream queries to a specific interface (auto detects the default physical interface; inherited automatically when TUN is active).
nameserver:
  - https://1.1.1.1/dns-query#PROXY
  - 223.5.5.5#interface=eth0

fallback-filter

Key Type Default Description
geoip bool true If nameserver returns an IP outside geoip-code, prefer fallback. If no mmdb is configured/loaded, the filter evaluates to true (uses fallback).
geoip-code string "CN" ISO country code (normalized to uppercase).
ipcidr list[CIDR] [] Results matching any of these CIDRs trigger fallback.
domain list[string] [] Queries matching these domains always use fallback.

Complete DNS Example

ipv6: true
mmdb: Country.mmdb

hosts:
  router.lan: 192.168.1.1

dns:
  enable: true
  ipv6: true
  use-hosts: true
  listen:
    udp: 127.0.0.1:5353
    tcp: 127.0.0.1:5353
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  fake-ip-filter:
    - "*.lan"
    - "+.local"
    - "time.windows.com"
  default-nameserver:
    - 223.5.5.5
    - 8.8.8.8
  proxy-server-nameserver:
    - https://dns.alidns.com/dns-query
  nameserver:
    - 223.5.5.5
    - 119.29.29.29
  fallback:
    - tls://1.1.1.1:853
    - https://dns.google/dns-query
  fallback-filter:
    geoip: true
    geoip-code: CN
    ipcidr:
      - 240.0.0.0/4
    domain:
      - "+.google.com"
      - "+.github.com"
  nameserver-policy:
    "+.internal.example.com": 192.168.1.1
  edns-client-subnet:
    ipv4: 198.51.100.0/24
  respect-rules: false