自建 DoH 分享与 Mihomo 配套配置
最初用 Adguard Home 部署,近期又接触了 Mosdns-x,又是一番折腾
完整的 mosdns-x 配置在最底下,有配套的数据看板
(需要 Mihomo 完整配置文件,其实写的一坨,想 “欣赏” 的可以留言 )
Adguard Home DoH 服务与 mihomo 配置
客户端说明:
ns:默认使用 NextDNS 与谷歌 dns 作为上游
m-cn:主要用于解析国内域名
m-psn:国内外上游,主要用于 proxy-server-nameserver
(m-psn,是因为之前用宝可梦,他家机场部分域名用国外 dns 获取不到结果,所以单独整了个 adgh 客户端用于 proxy-server-nameserver)
pure:纯净 dns,未开启广告拦截,使用 NextDNS 与谷歌 dns 作为上游
m-ad:为了方便看 adgh 的拦截日志,搞的客户端,上游同 ns(配置时使用 ns 就行)
DoH 地址:
两台 US 服务器部署:US2、US3
- https://us2.tls.vlo.cc/alicia/m-ad - https://us2.tls.vlo.cc/alicia/ns - https://us2.tls.vlo.cc/alicia/m-cn - https://us2.tls.vlo.cc/alicia/m-psn
- https://us3.tls.vlo.cc/alicia/m-ad - https://us3.tls.vlo.cc/alicia/m-psn - https://us3.tls.vlo.cc/alicia/m-cn - https://us3.tls.vlo.cc/alicia/ns
mihomo 配套的配置模板,使用 redir-host 模式
并不是最优配置,且这两个模块都引用了规则集:rule-set:,请替换为自己配置文件的规则集或者删除。
嗅探模块
# 流量嗅探 sniffer: enable: true force-dns-mapping: true parse-pure-ip: true override-destination: false sniff: HTTP: ports: [80, 8080-8880, 2052, 2082, 2086, 2095]
override-destination: true TLS: ports: [443, 8443, 2053, 2083, 2087, 2096]
QUIC: ports: [443, 8443, 2053, 2083, 2087, 2096]
skip-domain: - "rule-set:DW_Private,qiufeng_domain,Advertising,Tracking,MX_FCM" skip-src-address: - "rule-set:DW_PrivateIP,Advertising_IP" - 169.254.10.100/32 - febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128 skip-dst-address: - "rule-set:DW_PrivateIP,Advertising_IP" - 169.254.10.100/32 - febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128 - "rule-set:LL_TgIP,Skk_TgIP" hosts 与 dns 模块
# hosts模块
hosts:
'*.alicia.moe': 127.0.0.1
'alicia.moe': 127.0.0.1
'us3.tls.vlo.cc': 38.246.246.231
'us2.tls.vlo.cc': 154.37.208.14
'tls-us-2.vlo.cc': 38.244.62.224
'tls-us-1.vlo.cc': 154.37.208.14
'cn-09.api.vlo.cc': 38.244.62.224
'cn-05.api.vlo.cc': 154.37.208.14
# dns模块
dns:
enable: true
cache-algorithm: arc
prefer-h3: false
use-hosts: true
use-system-hosts: false
listen: 0.0.0.0:1053
ipv6: false
respect-rules: false
enhanced-mode: redir-host
fake-ip-range: 10.20.0.1/16
default-nameserver:
- quic://223.5.5.5
- tls://1.12.12.12
nameserver:
- https://us3.tls.vlo.cc/alicia/ns
- https://us2.tls.vlo.cc/alicia/ns
nameserver-policy:
"rule-set:mydns_domain,myblack_domain,qiufeng_domain,Advertising,Tracking":
- https://us2.tls.vlo.cc/alicia/m-ad
- https://us3.tls.vlo.cc/alicia/m-ad
"rule-set:MX_SteamCN,DW_GamesCN,Skk_Direct,Skk_Domestic,DW_CN,LL_China":
- https://us2.tls.vlo.cc/alicia/m-cn
- https://us3.tls.vlo.cc/alicia/m-cn
proxy-server-nameserver:
- https://us2.tls.vlo.cc/alicia/m-psn
- https://us3.tls.vlo.cc/alicia/m-psn
mosdns-x DoH 服务以及 mihomo 配置
直接在 mosdns-x 进行分流的。
AI 搓出来的数据面板:https://api.520924.xyz
DoH 地址:
同样在两台 US 服务器部署
- https://cn-05.api.vlo.cc/tls-cx - https://cn-09.api.vlo.cc/tls-cx
mihomo 配置:同样使用 redir-hosts 模式
嗅探模块
# 流量嗅探 sniffer: enable: true force-dns-mapping: true parse-pure-ip: true override-destination: false sniff: HTTP: ports: [80, 8080-8880, 2052, 2082, 2086, 2095]
override-destination: true TLS: ports: [443, 8443, 2053, 2083, 2087, 2096]
QUIC: ports: [443, 8443, 2053, 2083, 2087, 2096]
skip-domain: - "rule-set:DW_Private,qiufeng_domain,Advertising,Tracking,MX_FCM" skip-src-address: - "rule-set:DW_PrivateIP,Advertising_IP" - 169.254.10.100/32 - febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128 skip-dst-address: - "rule-set:DW_PrivateIP,Advertising_IP" - 169.254.10.100/32 - febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128 - "rule-set:LL_TgIP,Skk_TgIP" hosts 与 dns 模块
# hosts模块 hosts: '*.alicia.moe': 127.0.0.1 'alicia.moe': 127.0.0.1 'us3.tls.vlo.cc': 38.246.246.231 'us2.tls.vlo.cc': 154.37.208.14 'tls-us-2.vlo.cc': 38.244.62.224 'tls-us-1.vlo.cc': 154.37.208.14 'cn-09.api.vlo.cc': 38.244.62.224 'cn-05.api.vlo.cc': 154.37.208.14 # dns模块 dns: enable: true cache-algorithm: arc prefer-h3: false use-hosts: true use-system-hosts: false listen: 0.0.0.0:1053 ipv6: false respect-rules: false enhanced-mode: redir-host fake-ip-range: 10.20.0.1/16 default-nameserver: - quic://223.5.5.5 - tls://1.12.12.12 nameserver: - https://cn-05.api.vlo.cc/tls-cx - https://cn-09.api.vlo.cc/tls-cx proxy-server-nameserver: - https://us2.tls.vlo.cc/alicia/m-psn - https://us3.tls.vlo.cc/alicia/m-psn 折腾后记
自我感觉,自建 Adguard Home DoH 如果是搭配代理软件使用,可以在代理软件分流。
Adguard Home 可以配置不同客户端的上游,这让其在 mihomo 搭配使用时方便很多,毕竟直接在 Adguard Home 分流会很复杂且不易维护
如果你也在使用 Adguard Home + Mihomo,也可以尝试这样操作
MosDNS-X:
配置很复杂… 搞这个纯属折腾(确实是很折腾),配置文件抄的 easymosdns 的,然后用 Gemini Pro 网页版又搓了好久的数据面板:https://api.520924.xyz/
我的 mosdns-X 配置
# EasyMosdns v3.5(Final Release)
# https://apad.pro/easymosdns
log:
file: "./mosdns.log"
level: error
data_providers:
- tag: miaoerwlist
file: ./rules/miaoerwlist.txt
auto_reload: true
- tag: chinalist
file: ./rules/china_domain_list.txt
auto_reload: true
- tag: cnlistA
file: ./rules/cnlistA.txt
auto_reload: true
- tag: cdncn
file: ./rules/cdn_domain_list.txt
auto_reload: true
- tag: cdnnocn
file: ./rules/cdn_no_cn.txt
auto_reload: true
- tag: gfwlist
file: ./rules/gfw_domain_list.txt
auto_reload: true
- tag: gfwlistA
file: ./rules/gfwlistA.txt
auto_reload: true
- tag: chinaip
file: ./rules/china_ip_list.txt
auto_reload: true
- tag: cniplistA
file: ./rules/cniplistA.txt
auto_reload: true
- tag: gfwip
file: ./rules/gfw_ip_list.txt
auto_reload: true
- tag: adlist
file: ./rules/ad_domain_list.txt
auto_reload: true
- tag: miaoerblock
file: ./rules/miaoerblock.txt
auto_reload: true
- tag: ads
file: ./rules/ads.txt
auto_reload: true
- tag: ecscn
file: ./ecs_cn_domain.txt
auto_reload: true
- tag: ecsnoncn
file: ./ecs_noncn_domain.txt
auto_reload: true
- tag: hosts
file: ./hosts.txt
auto_reload: true
plugins:
# 数据统计插件
- tag: "metrics_data"
type: "metrics_collector"
# 广告拦截统计
- tag: "metrics_ad_blocked"
type: "metrics_collector"
# 本地上游统计
- tag: "metrics_local_up"
type: "metrics_collector"
# 本地备用上游统计
- tag: "metrics_localB_up"
type: "metrics_collector"
# 远程上游统计
- tag: "metrics_remote_up"
type: "metrics_collector"
# 远程备用上游统计
- tag: "metrics_remoteB_up"
type: "metrics_collector"
# 限制 EDNS0 UDP 缓冲大小的插件
- tag: udp_bufsize_limit
type: bufsize
args:
size: 1232 # 限制为 512 字节,强制大包回落到 TCP
# 缓存的插件
# [lan|wan]
- tag: cache_lan
type: cache
args:
size: 65536
compress_resp: true
#redis: "redis://127.0.0.1:6379/0"
lazy_cache_ttl: 86400
cache_everything: true
lazy_cache_reply_ttl: 1
- tag: cache_wan
type: cache
args:
size: 131072
compress_resp: true
#redis: "redis://127.0.0.1:6379/0"
lazy_cache_ttl: 86400
cache_everything: true
lazy_cache_reply_ttl: 5
# Hosts的插件
- tag: hosts
type: hosts
args:
hosts:
- "provider:hosts"
# 获取ECS的插件
- tag: ecs_auto
type: ecs
args:
auto: true
force_overwrite: false
# 指定ECS的插件
# [local|global]
- tag: ecs_local
type: ecs
args:
auto: false
ipv4: "101.6.6.0"
ipv6: "2001:da8::"
force_overwrite: false
- tag: ecs_global
type: ecs
args:
auto: false
ipv4: "168.95.1.0"
ipv6: "2001:b000:168::"
force_overwrite: false
# 匹配ECS的插件
- tag: ecs_is_local
type: query_matcher
args:
ecs:
- "101.6.6.0/24"
- "2001:da8::/48"
- tag: ecs_is_lan
type: query_matcher
args:
ecs:
- "0.0.0.0/8"
- "10.0.0.0/8"
- "100.64.0.0/10"
- "127.0.0.0/8"
- "169.254.0.0/16"
- "172.16.0.0/12"
- "192.0.0.0/24"
- "192.0.2.0/24"
- "198.18.0.0/15"
- "192.88.99.0/24"
- "192.168.0.0/16"
- "198.51.100.0/24"
- "203.0.113.0/24"
- "224.0.0.0/3"
- "::1/128"
- "fc00::/7"
- "fe80::/10"
- tag: ecs_is_cn
type: query_matcher
args:
ecs:
- "provider:chinaip"
- "provider:cniplistA"
# 调整TTL的插件
# [1m|5m|1h]
- tag: ttl_1m
type: ttl
args:
minimal_ttl: 60
maximum_ttl: 3600
- tag: ttl_5m
type: ttl
args:
minimal_ttl: 300
maximum_ttl: 86400
- tag: ttl_1h
type: ttl
args:
minimal_ttl: 3600
maximum_ttl: 86400
# 匹配TYPE12类型请求的插件
- tag: qtype12
type: query_matcher
args:
qtype: [12]
# 匹配TYPE65类型请求的插件
- tag: qtype65
type: query_matcher
args:
qtype: [65]
# 匹配TYPE255类型请求的插件
- tag: qtype255
type: query_matcher
args:
qtype: [255]
# 匹配RCODE2的插件
- tag: response_server_failed
type: response_matcher
args:
rcode: [2]
# 屏蔽请求的插件
- tag: black_hole
type: blackhole
args:
rcode: 0
ipv4: "169.254.10.100"
ipv6: "febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
# 匹配无效域名的插件
- tag: query_is_non_domain
type: query_matcher
args:
domain:
- "keyword::"
# 匹配本地域名的插件
- tag: query_is_local_domain
type: query_matcher
args:
domain:
- "provider:chinalist"
- "provider:cnlistA"
# 匹配污染域名的插件
- tag: query_is_non_local_domain
type: query_matcher
args:
domain:
- "provider:gfwlist"
- "provider:gfwlistA"
# 匹配CDN域名的插件
- tag: query_is_cdn_cn_domain
type: query_matcher
args:
domain:
- "provider:cdncn"
- tag: query_is_cdn_no_cn_domain
type: query_matcher
args:
domain:
- "provider:cdnnocn"
# 匹配白名单域名的插件
- tag: query_is_whitelist_domain
type: query_matcher
args:
domain:
- "provider:miaoerwlist"
# 匹配广告域名的插件
- tag: query_is_ad_domain
type: query_matcher
args:
domain:
- "provider:adlist"
- "provider:miaoerblock"
- "provider:ads"
# 匹配强制本地解析域名的插件
- tag: query_is_cn_domain
type: query_matcher
args:
domain:
- "provider:ecscn"
# 匹配强制非本地解析域名的插件
- tag: query_is_noncn_domain
type: query_matcher
args:
domain:
- "provider:ecsnoncn"
# 匹配本地IP的插件
- tag: response_has_local_ip
type: response_matcher
args:
ip:
- "provider:chinaip"
- "provider:cniplistA"
# 匹配污染IP的插件
- tag: response_has_gfw_ip
type: response_matcher
args:
ip:
- "provider:gfwip"
# 转发至本地服务器的插件
- tag: forward_local
type: fast_forward
args:
upstream:
- addr: "h3://dns.alidns.com"
dial_addr: "223.5.5.5"
- addr: "tls://dot.pub"
dial_addr: "1.12.12.21"
bootstrap: "121.4.4.95"
enable_pipeline: true
max_conns: 3
# 转发至远程服务器的插件
- tag: forward_remote
type: fast_forward
args:
upstream:
- addr: "tls://8.8.8.8"
enable_pipeline: true
max_conns: 4
- addr: "tls://dns.nextdns.io"
bootstrap: "8.8.8.8"
enable_pipeline: true
max_conns: 4
# 转发至分流服务器的插件
- tag: forward_localReserve
type: fast_forward
args:
upstream:
- addr: "quic://dns.alidns.com"
dial_addr: "223.6.6.6"
- addr: "tls://dot.pub"
dial_addr: "1.12.34.56"
bootstrap: "121.4.4.95"
enable_pipeline: true
max_conns: 3
- tag: forward_remoteReserve
type: fast_forward
args:
upstream:
- addr: "tls://8.8.4.4"
enable_pipeline: true
max_conns: 4
- addr: "tls://dns.nextdns.io"
bootstrap: "8.8.8.8"
enable_pipeline: true
max_conns: 4
# 主要的运行逻辑插件
# sequence 插件中调用的插件 tag 必须在 sequence 前定义
# 否则 sequence 找不到对应插件
- tag: main_sequence
type: sequence
args:
exec:
- metrics_data
# 域名映射IP
- hosts
# 屏蔽TYPE65与无效类型请求
- if: "[qtype65] || (query_is_non_domain)"
exec:
- _new_nxdomain_response
- _return
# 优化PRT与ANY类型请求
- if: "[qtype12] || [qtype255]"
exec:
- _no_ecs
- forward_local
- ttl_1h
- _return
# 缓存ECS
- ecs_auto
- _edns0_filter_ecs_only
- udp_bufsize_limit
- if: ecs_is_lan
exec:
- cache_lan
- _no_ecs
else_exec:
- cache_wan
# 强制用本地服务器解析
- if: query_is_cn_domain
exec:
- forward_local
- ttl_5m
- _return
# 强制用非本地服务器解析
- if: query_is_noncn_domain
exec:
# 优先返回ipv4结果
- _prefer_ipv4
- ecs_global
- primary:
# 默认用分流服务器
- forward_remote
secondary:
# 超时用远程服务器
- forward_remoteReserve
fast_fallback: 2500
always_standby: false
- ttl_5m
- _return
# 已知的白名单域名用本地服务器解析
- if: query_is_whitelist_domain
exec:
# 默认用本地服务器
- metrics_local_up
- forward_local
- ttl_1m
# 预防已知的本地域名临时污染
- if: response_has_gfw_ip
exec:
- metrics_remote_up
- ecs_local
- forward_remote
- _return
# 屏蔽广告域名
- if: query_is_ad_domain
exec:
- metrics_ad_blocked
- black_hole
- ttl_1h
- _return
# 已知的本地域名或CDN域名用本地服务器解析
- if: "(query_is_local_domain) || (query_is_cdn_cn_domain)"
exec:
# 默认用本地服务器
- metrics_local_up
- forward_local
- ttl_1m
# 预防已知的本地域名临时污染
- if: response_has_gfw_ip
exec:
- metrics_remote_up
- ecs_local
- forward_remote
- _return
# 已知的非大陆CDN域名
- if: query_is_cdn_no_cn_domain
exec:
# 优先返回ipv4结果
- _prefer_ipv4
- primary:
# 默认用分流服务器
- metrics_remote_up
- forward_remote
secondary:
# 超时用远程服务器
- metrics_remoteB_up
- forward_remoteReserve
fast_fallback: 2500
always_standby: false
- ttl_5m
- _return
# 已知的污染域名用分流服务器或远程服务器解析
- if: query_is_non_local_domain
exec:
# 优先返回ipv4结果
- _prefer_ipv4
- ecs_global
- primary:
# 默认用分流服务器
- metrics_remote_up
- forward_remote
secondary:
# 超时用远程服务器
- metrics_remoteB_up
- forward_remoteReserve
fast_fallback: 2500
always_standby: false
- ttl_5m
- _return
# 剩下的未知域名用IP分流
# 优先返回ipv4结果
- _prefer_ipv4
- primary:
# 默认用分流服务器
- metrics_remote_up
- ecs_local
- forward_remote
- if: "(ecs_is_cn) && (response_has_local_ip) || [response_server_failed]"
exec:
- metrics_localB_up
- forward_localReserve
- _return
secondary:
# 超时用本地分流器
- metrics_remote_up
- forward_remote
- if: response_has_local_ip
exec:
- metrics_localB_up
- forward_localReserve
- _return
fast_fallback: 2500
always_standby: false
- ttl_5m
servers:
- exec: main_sequence
timeout: 10
listeners:
- protocol: http
addr: "0.0.0.0:9053"
url_path: "/tls-cx"
get_user_ip_from_header: "X-Forwarded-For"
kernel_tx: true
kernel_rx: true
api:
http: "127.0.0.1:9080"
如果需要 mosdns-x 面板文件的,https://api.520924.xyz/mosdns-x-webui.zip 可以下载,根据自己配置文件修改,或者扔给 Gemini 修改
搭建的都是 US 服务器,应该都有 9929 线路,可以直连(域名不要搞得像机场域名那种二级域名格式,带 tls、us 这些,可能会被阻断域名)
欢迎留言使用体验 我自己是用不出来 Adguard Home 与 Mosdns-x 搭建的在使用上的性能区别,总体还是 Adguard Home 方便

