Client 客户端 Router 路由器 Client->Router Dae Dae Router->Dae 劫持DNS请求 AdGuardHome AdGuardHome :53 Dae->AdGuardHome 转发 SmartDNS SmartDNS 默认监听::6053 第二DNS::5335 AdGuardHome->SmartDNS 转发 BlackHole BlackHole AdGuardHome->BlackHole 广告相关DNS丢弃 Ali_DNS Ali DNS 223.5.5.5:53 SmartDNS->Ali_DNS 直接发起请求 Google_DNS Google DNS 8.8.8.8:53 SmartDNS->Google_DNS 通过dae代理向外请求 DNS查询请求
网络传输 特定客户端网络流量 Client 特定客户端 Router 路由器 Client->Router Dae Dae Router->Dae 转发 代理出口 代理出口 Dae->代理出口 分流 路由表 路由表 Dae->路由表 直连 国内出口 国内出口 路由表->国内出口 默认 Wireguard 其他网段 路由表->Wireguard 特定IP段 特定客户端网络流量
普通客户端网络流量 Client 普通客户端 Router 路由器 Client->Router Dae Dae Router->Dae 转发 路由表 路由表 Dae->路由表 直连 国内出口 国内出口 路由表->国内出口 默认 Wireguard Wireguard 路由表->Wireguard 特定IP段 普通客户端网络流量
配置 Immortalwrt 配置 安装教程很多,我使用的immortalwrt-23.05.4-x86-64-generic-ext4-combined-efi.img
,安装在 N100
的 ESXi
中。 在 ESXi
载入后使用 gparted
扩盘到2G
smartdns 上游服务器 两组或更多组的服务器,根据域名进行分类。 一般规则默认是命中 gfw.list
中的域名专门走海外DNS,剩余使用国内DNS查询
第二DNS服务器配置 第二服务器是不会进行分流的,都会通过服务器组配置走流量
开启配置 停用IPV6地址解析
修改 服务器组
为 fq_dns
下载文件配置 这里用来下载远端配置文件,并且定时更新 主要来自 V2Ray 路由规则加强版 这里额外下载了 geosite
和 geoip
在dae中会用到
域名规则配置 这里可以基于上面下载的域名文件来进行分流 无其实是走默认,可以不配置
规则名称 服务器组 域名列表文件 gfw.txt fq_dns /etc/smartdns/domain-set/gfw.txt proxy-list.txt fq_dns /etc/smartdns/domain-set/proxy-list.txt china-list.txt 无 /etc/smartdns/domain-set/china-list.txt win-update.txt 无 /etc/smartdns/domain-set/win-update.txt google-cn.txt 无 /etc/smartdns/domain-set/google-cn.txt apple-cn.txt 无 /etc/smartdns/domain-set/apple-cn.txt
AdGuardHome 上游DNS服务器
-> udp://127.0.0.1:6053
监听端口
-> 53
Dnsmasq 由于更改 AdGuardHome
在 53
监听,需要将 Dnsmasp
的DNS服务器端口设置0。才能启动
DHCP 由于关闭 Dnsmasq
的 DNS Server
,在默认的 DHCP
不会下发默认 DNS Server
需要在 接口|DHCP|高级设置|DHCP选项
加上 6,
+ DNS Server IP
;如 6,10.0.0.0
通告额外 DNS Server
DAED 配置 geoip & geosite 自动更新 使用 ln -s
, 将 SmartDNS
下载的 dat
文件,软链到 /etc/daed
中
1 2 ln -s /etc/smartdns/download/geoip.dat /etc/daed/geoip.datln -s /etc/smartdns/download/geosite.dat /etc/daed/geosite.dat
Global 连接选项 | 拨号模式
-> domain+
连接选项 | TLS实现
-> utls
连接选项 | uTLS模仿
-> chrome_auto
DNS 1 2 3 4 5 6 7 8 upstream { adguard: 'udp://127.0.0.1:53' } routing { request { fallback: adguard } }
路由 路由由以下几个部分组成,优先配置直连的规则,最后使用分流兜底。
DNS相关配置 dae 默认会劫持DNS请求,使用 must_direct 代表请求不会被劫持 这里 pname
指的是 Openwrt
中跑的进程,可以用 ps
找到
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # 进程级的豁免 pname(NetworkManager, systemd-resolved, dnsmasq) -> must_direct pname(AdGuardHome) -> must_direct pname(smartdns) && l4proto(udp) && dport(53) -> must_direct # CN DOH 不走代理 dip(223.5.5.5/32) -> direct dip(223.6.6.6/32) -> direct dip(1.12.12.12/32) -> direct dip(120.53.53.53/32) -> direct # GW DOH 走代理 dip(8.8.8.8/32) -> proxy dip(8.8.4.4/32) -> proxy dip(1.1.1.1/32) -> proxy dip(1.0.0.1/32) -> proxy
客户机直连设置 我的网段为 30.1.0.0/22,普通设备没有分流需求,所以做额外指定
1 2 3 4 5 6 7 # Client # 在 30.1.0.0/22 范围内,除了 `30.1.1.0/25` 的IP段都直接访问网络 sip(30.1.0.0/22) && !sip(30.1.1.0/25)-> direct # 也可以使用 mac 分流 mac('00:00:00:00:00:00') -> direct
内网地址直连 1 2 3 4 5 6 7 # LOCAL # 可选,我的内网范围在 `30.0.0.0/8` 是属于 `DOD` 的IP网段,所以得直连。 dip(30.0.0.0/8) -> direct dip(geoip:private) -> direct
分流规则 1 2 3 4 5 6 7 8 9 10 # 国内网段直连 dip(geoip:cn) -> direct domain(geosite:apple-cn) -> direct domain(geosite:gfw) -> proxy domain(geosite:china-list) -> direct domain(geosite:cn) -> direct # 兜底 fallback: proxy
WireGuard Client 配置 新增一个 Interface
,协议选择 WireGuard VPN
。配置好相关参数。 新增防火墙WG
,开启 MSS 钳制
。参考 OpenWrt 中的 MSS 钳制是干什么用的 新增 LAN
->WG
转发,参考 LAN
-> WAN
的规则 详细配置如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 # /etc/config/network config interface 'wg' option proto 'wireguard' option private_key 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=' list addresses '30.xx.1.0/32' list addresses 'xxxx:xxxx:7:0:1::1/128' option mtu '1280' config wireguard_wg option public_key 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=' option persistent_keepalive '21' option endpoint_host '30.xx.1.xx' option endpoint_port '655xx' option route_allowed_ips '1' list allowed_ips '30.xx.0.0/18' list allowed_ips '10.0.0.0/8' list allowed_ips 'fe80::/64' list allowed_ips 'fdbd::/16'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 # /etc/config/firewall config zone option name 'wg' option input 'REJECT' option output 'ACCEPT' option forward 'REJECT' list network 'wg' option masq '1' option masq6 '1' option mtu_fix '1' config forwarding option src 'lan' option dest 'wg'