Skip to content

Instantly share code, notes, and snippets.

@rampageX
Last active December 25, 2021 03:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rampageX/4ac5de7fb3a824c8c1adeea0881ff6ad to your computer and use it in GitHub Desktop.
Save rampageX/4ac5de7fb3a824c8c1adeea0881ff6ad to your computer and use it in GitHub Desktop.
mosdns local config for v2.x
log:
# level: error # 日志级别。可选 `debug` `info` `warn` `error`。默认 `info`。
# file: "/var/log/mosdns.log" # 记录日志到文件。
level: debug
file: ""
plugin:
## 启动 sequence 服务器
- tag: sequence_server
type: server
args:
max_concurrent_queries: 0
entry: main_sequence
server:
- protocol: udp
addr: :544
- protocol: tcp
addr: :544
## 启动 sequence fast 服务器
- tag: sequence_server_fast
type: server
args:
max_concurrent_queries: 0
entry: main_sequence
server:
- protocol: udp
addr: :555
- protocol: tcp
addr: :555
## 可执行插件-顺序
- tag: main_sequence
type: sequence
args:
exec:
- _default_cache # 缓存
- if:
- match_local_domain # 处理已知的本地域名
- "!_query_is_common" # 和不常见的请求类型
exec:
- ecs_local
- forward_local
#- force_ttl
- _end
- if:
- match_non_local_domain # 处理已知的非本地域名
exec:
- ecs_remote
- forward_remote
#- force_ttl
- _end
- sequence_bypass_local # 分流未知域名。
## 可执行插件-并发
- tag: main_sequence_fast
type: sequence
args:
exec:
- _default_cache # 缓存
- if:
- match_local_domain # 处理已知的本地域名
- "!_query_is_common" # 和不常见的请求类型
exec:
- ecs_local
- fast_forward_local
#- force_ttl
- _end
- if:
- match_non_local_domain # 处理已知的非本地域名
exec:
- ecs_remote
- fast_forward_remote
#- force_ttl
- _end
- sequence_bypass_local_fast # 分流未知域名。
## 分流逻辑 顺序分流
- tag: sequence_bypass_local # 顺序执行的分流
type: sequence
args:
exec:
- forward_local # 先请求转发至本地服务器
#- force_ttl
- if:
- match_local_ip # 如果应答包含本地 IP
exec:
- _end # 就直接采用结果
- forward_remote # 否则用远程服务器的结果
#- force_ttl
## 分流逻辑 并发分流
- tag: sequence_bypass_local_fast # 顺序执行的分流
type: sequence
args:
exec:
- primary:
- fast_forward_local
- if:
- '!match_local_ip'
exec:
- _drop_response
secondary:
- fast_forward_remote
fast_fallback: 50 # 这里建议设置成 local 服务器正常延时的 2~5 倍。
# 这个延时保证了 local 延时偶尔变高时,其结果不会被 remote 抢答。
# 如果 local 超过这个延时还没响应,可以假设 local 出现了问题。
# 这时用就采用 remote 的应答。
always_standby: true
## 匹配器插件
# - tag: match_qtype_HTTPS # 匹配 HTTPS 请求
# type: query_matcher
# args:
# type: [65]
- tag: match_local_domain # 匹配请求域名是否是本地域名
type: query_matcher
args:
domain:
- "ext:/root/cfg/geosite.dat:cn"
- tag: match_non_local_domain # 匹配请求域名是否是境外域名
type: query_matcher
args:
domain:
- "ext:/root/cfg/domain_gfwlist.txt"
- tag: match_local_ip # 匹配应答的 IP 是否是本地 IP
type: response_matcher
args:
ip:
- "ext:/root/cfg/geoip-only-cn-private.dat:cn"
## ECS
- tag: ecs_local
type: ecs
args:
auto: false # 是否根据客户端地址自动附加 ECS。如果为 true,则预设地址不会被使用。
force_overwrite: false # 如果请求已有 ECS,是否覆盖。
mask4: 24 # 用于 ipv4 地址的掩码。
mask6: 32 # 用于 ipv6 地址的掩码。
ipv4: "120.230.137.0" # 预设的 ipv4 地址。如果非空,会附加在 A 请求中。
ipv6: "" # 预设的 ipv6 地址。如果非空,会附加在 AAAA 请求中。
- tag: ecs_remote
type: ecs
args:
auto: false
force_overwrite: false
mask4: 24
mask6: 32
ipv4: "202.67.222.0"
ipv6: ""
- tag: force_ttl
type: ttl
args:
minimal_ttl: 86400 # 最小TTL。如果非零,小于这个数的应答的TTL会被修改成这个值。
maximum_ttl: 604800 # 最大TTL。如果非零,大于这个数的应答的TTL会被修改成这个值。
# 功能性插件
- tag: forward_local # 转发至本地服务器
type: forward
args:
upstream:
- addr: 127.0.0.1:533
trusted: true
- addr: 211.136.192.6:53
- addr: 120.196.165.24:53
# - addr: https://doh.360.cn/dns-query
# - addr: https://i.233py.com/dns-query
- addr: tls://dns.alidns.com
trusted: true
# - addr: tls://dns.pub
# trusted: true
# insecure_skip_verify: false # 禁用 TLS 身份验证。
# fastest_ip: false # 最快 IP 模式。
# timeout: 3 # 超时时间,单位: 秒。
# bootstrap:
# - 9.9.9.9:9953
# - 208.67.220.220:443
- tag: forward_remote # 转发至远程服务器
type: forward
args:
upstream:
- addr: 127.0.0.1:4433
trusted: true
# - addr: https://dns11.quad9.net/dns-query
# trusted: true
# - addr: https://dns.twnic.tw/dns-query
# trusted: true
# - addr: tls://8.8.8.8
# trusted: true
# - addr: tls://8.8.4.4
# trusted: true
# - addr: https://249749.xyz/dns-query
# trusted: true
# - addr: https://quakemachinex.com/dns-query
# trusted: true
# insecure_skip_verify: false
# fastest_ip: false
# timeout: 6
# bootstrap:
# - 9.9.9.9:9953
# - 208.67.220.220:443
- tag: fast_forward_local
type: fast_forward
args:
timeout: 3 # 请求超时时间。单位: 秒。默认 5。
upstream: # 上游服务器。至少要配置一个。可配置多个,会并发请求全部服务器。
- addr: 127.0.0.1:533
trusted: true
- addr: 'tls://dns.alidns.com' # 服务器地址。必需。
dial_addr: 223.5.5.5:853 # 指定服务器网络地址。格式 `host:port`,端口不可省略。
# trusted: false # 是否是可信服务器。仅配置了多个服务器时生效。
# true: 该服务器返回的 Rcode != 0 的应答会被接受。
# false: 该服务器返回的 Rcode != 0 会被丢弃。
# socks5: "" # socks5 服务器地址。格式 `host:port`。`:port` 不可省略。
# 不支持用户名密码认证。适用于 `tcp`, `dot`, `doh` 协议。
# max_conns: 1 # 最大连接数。目前仅适用于 `doh` 协议。默认: 1。
# idle_timeout: 10 # 空连接超时时间。单位: 秒。
# 如果为 0,则禁用连接重用(对于 `udp` 协议是禁用套接字重用)。适用于全部协议。
# insecure_skip_verify: false # 是否禁用 TLS 验证。适用于 `dot`,`doh` 协议。
# - addr: 'tls://dns.pub'
# dial_addr: 162.14.21.56:853
# trusted: false
# socks5: ""
# max_conns: 1
# idle_timeout: 10
# insecure_skip_verify: false
- tag: fast_forward_remote
type: fast_forward
args:
timeout: 3
upstream:
- addr: 127.0.0.1:4433
trusted: true
# - addr: 'tls://dns11.quad9.net'
# dial_addr: 9.9.9.11:853
# trusted: true
# socks5: "127.0.0.1:7575"
# max_conns: 1
# idle_timeout: 30
# insecure_skip_verify: false
# - addr: 'tls://dns.google'
# dial_addr: 8.8.4.4:853
# trusted: true
# socks5: "127.0.0.1:7575"
# max_conns: 1
# idle_timeout: 30
# insecure_skip_verify: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment