折腾了一堆nftables和iptables方法把网络流量送到clash透明代理端口,偶然发现Clash.meta的tun模式实现了所有
这里在树莓派5,Raspberry Pi OS 系统 (debian系) 测试成功
要实现完整的路由器功能,只需要配置一下 mihomo 的 tun 模式和自带的 dns 转发服务器即可,参考下面配置,tun 和 dns 块可以直接抄,除了代理节点、代理组、规则要自己写。如果不成功,可以试试打开 Linux 内核转发功能
Linux 部署 mihomo 可以看我的另一篇教程:Linux 搭建 Clash WebUI(无桌面环境)|枯死的灌木
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| external-controller: '0.0.0.0:9090'
tun: enable: true stack: mixed auto-route: true auto-redirect: true auto-detect-interface: true dns-hijack: - any:53 - tcp://any:53 device: mihomo mtu: 9000 strict-route: false gso: true gso-max-size: 65536 udp-timeout: 300 iproute2-table-index: 2022 iproute2-rule-index: 9000 endpoint-independent-nat: false route-exclude-address: - 172.16.0.0/12 - 192.168.0.0/16 - fc00::/7
dns: enable: true listen: 0.0.0.0:53 ipv6: false default-nameserver: [223.5.5.5, 119.29.29.29] enhanced-mode: fake-ip fake-ip-range: 198.18.0.1/16 use-hosts: true nameserver: ['https://doh.pub/dns-query', 'https://dns.alidns.com/dns-query'] fallback: ['https://doh.dns.sb/dns-query', 'https://dns.cloudflare.com/dns-query', 'https://dns.twnic.tw/dns-query', 'tls://8.8.4.4:853'] fallback-filter: { geoip: true, ipcidr: [240.0.0.0/4, 0.0.0.0/32] }
proxies:
proxy-groups:
rules:
|
然后把其他设备的网关和 dns 指到刚才配置的 linux 主机即可
