# ============================================ # MosDNS v5 核心配置(精简版 - 首次启动使用) # 此文件不包含 include,可以直接启动 # 启动后通过 Web UI 添加规则,然后使用 config-template.yaml # ============================================ log: level: info # 管理 API api: http: "0.0.0.0:5541" # Web 管理界面 web: http: "0.0.0.0:5555" # 注意:此配置不包含动态规则引入 # 1. 首次启动后,通过 Web UI (http://IP:5555) 添加域名路由规则 # 2. 添加规则后,规则文件会自动保存到 config.d/rules/ 目录 # 3. 然后取消注释下面的 include 行,或使用 config-template.yaml # # include: # - "./config.d/rules/*.yaml" plugins: # ========= 基础能力:DNS 服务器 ========= # 能力 1: 国内 DNS(多个上游并发) - tag: china-dns type: forward args: concurrent: 6 upstreams: - addr: "udp://223.5.5.5" # 阿里 DNS - addr: "udp://114.114.114.114" # 114 DNS - addr: "udp://119.29.29.29" # 腾讯 DNS - addr: "udp://180.76.76.76" # 百度 DNS - addr: "udp://202.96.128.86" # 江苏电信 - addr: "udp://202.96.128.166" # 江苏电信备用 # 能力 2: 国外 DNS - Cloudflare(DoT 加密) - tag: overseas-dns-cloudflare type: forward args: concurrent: 2 upstreams: - addr: "tls://1dot1dot1dot1.cloudflare-dns.com" dial_addr: "1.1.1.1" enable_pipeline: true - addr: "tls://1dot1dot1dot1.cloudflare-dns.com" dial_addr: "1.0.0.1" enable_pipeline: true # 能力 3: 国外 DNS - Google(DoT 加密) - tag: overseas-dns-google type: forward args: concurrent: 2 upstreams: - addr: "tls://dns.google" dial_addr: "8.8.8.8" enable_pipeline: true - addr: "tls://dns.google" dial_addr: "8.8.4.4" enable_pipeline: true # 能力 4: 混合 DNS(先国外,超时/失败则国内) - tag: hybrid-dns type: fallback args: primary: overseas-dns-cloudflare secondary: china-dns threshold: 500 always_standby: true # ========= 基础能力:IP 地理位置判断 ========= - tag: geoip_cn type: ip_set args: files: - "/usr/local/yltx-dns/config/cn.txt" # ========= 基础能力:缓存 ========= - tag: cache type: cache args: size: 82768 lazy_cache_ttl: 43200 # ========= 基础能力:辅助序列 ========= # 便捷封装:国内 DNS - tag: forward_local_upstream type: sequence args: - exec: prefer_ipv4 - exec: query_summary forward_local - exec: $china-dns # 便捷封装:国外 DNS(Cloudflare) - tag: forward_remote_upstream type: sequence args: - exec: prefer_ipv4 - exec: query_summary forward_remote - exec: $overseas-dns-cloudflare # 能力 5: 智能防污染(先国内,返回国外 IP 则用国外 DNS) - tag: smart_anti_pollution type: sequence args: - exec: prefer_ipv4 - exec: $forward_local_upstream - matches: resp_ip $geoip_cn exec: accept - exec: $forward_remote_upstream - exec: query_summary anti_pollution_fallback # 检查是否有响应 - tag: has_resp_sequence type: sequence args: - matches: has_resp exec: accept # 拒绝无效查询 - tag: reject_invalid type: sequence args: - matches: qtype 65 exec: reject 3 # ========= 主序列 ========= - tag: main_sequence type: sequence args: # 1. 缓存检查 - exec: $cache # 2. 拒绝无效查询 - exec: $reject_invalid - exec: jump has_resp_sequence # 3. 动态规则处理(通过 include 引入的规则会在这里生效) # 注意:首次启动时,config.d/rules/ 目录为空,所有查询会走默认处理 # 4. 默认处理:未匹配任何规则的查询使用国内 DNS - exec: prefer_ipv4 - exec: $china-dns - exec: accept # ========= 服务监听 ========= - tag: udp_server type: udp_server args: entry: main_sequence listen: ":531" - tag: tcp_server type: tcp_server args: entry: main_sequence listen: ":531"