169 lines
4.2 KiB
YAML
169 lines
4.2 KiB
YAML
# ============================================
|
||
# MosDNS v5 核心能力定义
|
||
# 此文件定义所有可用的 DNS 能力
|
||
# 具体策略由 config.d/ 目录中的文件定义
|
||
# ============================================
|
||
|
||
log:
|
||
level: info
|
||
|
||
# 管理 API
|
||
api:
|
||
http: "0.0.0.0:5541"
|
||
|
||
# Web 管理界面
|
||
web:
|
||
http: "0.0.0.0:5555"
|
||
|
||
# 引入动态配置(域名路由规则)
|
||
# 注意:首次启动前请先创建目录,或注释掉此行
|
||
# 创建目录:mkdir -p ./config.d/rules
|
||
# 如果目录不存在或为空,请先注释掉下面的 include,启动后通过 Web UI 添加规则
|
||
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 引入的规则会在这里生效)
|
||
# 例如:rule_openai, rule_netflix 等会自动注入
|
||
|
||
# 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"
|
||
|