首先说我的需求,第一当然是科学上网,第二是我的群晖需要用 ipv6 暴露在外网。所以我的网络需要开启 ipv6 ,包括 dns 也需要允许 ipv6.下面是我的优化方案:
1 、基本的上网配置是 dnsmasq+openclash+smartdns, openclash 劫持 dnsmasq 的 53 端口,然后将 dns 转发到 smartdns 的 5335 端口,smartdns 国内域名向我的上游 dns 解析,国外域名通过 doh/dot 解析。类似于这样的配置:
domain-set -name chinalist -file /etc/smartdns/domain-set/accelerated-domains.china.domain.smartdns.conf
domain-rules /domain-set:chinalist/ -nameserver domestic -speed-check-mode ping,tcp:80,tcp:443 -address #4,#6 -dualstack-ip-selection yes -response-mode first-ping
domain-rules /./ -nameserver gw -speed-check-mode none -address -6 dualstack-ip-selection no -response-mode fastest-response
这里,国内域名可以解析 ipv4 和 ipv6 地址,国外域名就只解析 ipv4 地址。
2 、openclash 使用 redir-host 模式,之所以不使用 fakeip ,是因为我来需要 ssh 连接外网,用 fakeip 会出各种奇怪的问题。然后选择“自定义上游 DNS 服务器”,所有上游服务器都设置成 smartdns 的 5335 端口。这样把 dns 交给 smartdns 分流,smartdns 如果使用 doh 查询 1.1.1.1 或者 google 的 dns ,又会转到 openclash 翻墙。 之所以不把 smartdns 放最前面,是因为 openclash 通过域名去分流更精准一些。
3 、openclash 不做 ipv6 的代理,因为上面说了,国外域名只会解析 ipv4 地址。
4 、在 openclash 开发者选项增加 iptables 规则,这样当国内域名解析 ipv4 后,直接就通过网络出去了,而不走 clash 代理,在插件设置-->开发者选项里增加两行脚本:
LOG_OUT "Tip: Start Add Custom Firewall Rules..."
iptables -t nat -I openclash -m set --match-set china_ip_route dst -j RETURN
iptables -t mangle -I openclash_output -m set --match-set china_ip_route dst -j RETURN
利用 openclash 自己同步的 ipset 规则来讲解析到的国内 ip 地址直接跳转而不走 clash 代理通道。第一条是路由规则,第二条是本机规则。
5 、使用 github cmliu 大神的 edgetunnel 项目,在 cf 上弄了个代理,然后又用 CF-Workers-SUB 项目,将我买的收费机场和 cf 的免费机场做了一个聚合。最后 fork cmliu 大神的 ACL4SSR 项目,定制了我的分流规则,使 openclash 自动订阅我的 https://fgfwsub.xxxx.site/<uuid>即可自动获取机场订阅信息。当我的机场发生改变的时候,只需要去这个网址上去修改机场聚合地址就可以了 。当我需要设置新的分流规则,只需要在我 fork 的 ACL4SSR 项目里,修改对应的分流规则即可。具体可以参照油罐该大神的视频。
春节以来,零零碎碎折腾了好久,总算折腾得好用了。
|