diff --git a/README.md b/README.md index ce123fb..4d345f9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,76 @@ # clash_tun-for-Miwifi 在小米AX3600/AX1800/AX5等路由器上使用clash_tun模式做透明代理 +===== +PS: +-- +支持ss,v2ray,trojan,但不支持ssr,也不支持订阅(需要自行编辑config.yaml以配置服务器)
+小米路由内置的openwrt默认阉割了对tproxy的支持,所以使用redir模式做透明代理时无法转发udp流量,只能采用tun模式转发udp流量
+tun模式对udp的转发支持非常好,而且延迟非常低,小米官方内置的tx网游加速器其实就是使用的tun模式
+clash对tun模式的官方文档内容不是很完善,折腾了好几天也没搞懂怎么使用真实ip模式进行透明代理,故只能采用配置相对简单的fake-ip模式
+fake-ip模式在数据向dns查询时默认会返回例如198.18.0.x这样的虚拟ip地址,故部分必须验证真实ip地址的网站或app可能会受影响
+系统默认的dnsmasq会强行劫持所有53端口流量,所以必须修改dnsmasq的默认端口以让流量经过clash内置的dns服务以使用fake-ip模式
+fake-ip+tun模式的透明代理方式可能适用于大部分同样采用openwrt内核的路由器或者软路由,有需求的可以自行斟酌使用
+ +使用依赖: +-- +请确认路由器或设备已经开启ssh并获取root权限,小米AX系列可参考:https://www.right.com.cn/forum/thread-4032490-1-1.html
+ssh工具或telent工具,例如putty,bitvise
+scp工具,如winscp(内置了putty,注意小米AX系列没有内置sftp服务,而是内置了scp服务)
+ +使用方式: +-- +下载clash.zip https://github.com/juewuy/clash_tun-for-Miwifi/raw/master/clash.zip 并解压
+根据自己需求参考备注修改config.yaml配置文件`重要!!!`
+也可以自行下载或更新clash-tun模式核心文件并重命名为clash https://github.com/Dreamacro/clash/releases/tag/premium (小米AX系列都是armv7架构,其他路由器请自查)
+将clash文件夹以及内部4个文件通过winSCP上传到路由器/etc文件夹下(最终应该是/etc/clash/……)
+在ssh中用root用户执行下方的相应命令即可!(理论上非root用户也可以运行,请参考官方文档自行研究)
+ +启用后可以通过 http://clash.razord.top 管理clash内置规则,无需其他额外设置即可正常使用
+也可以自行配置http代理(端口7890)或者sock5代理(端口7891)(速度比tun模式更快但是相对延迟可能略高)
+```sh +#首次启用clash +mv /etc/clash/clashservice /etc/init.d/clash #将clash服务文件移动到系统目录 +chmod 777 /etc/clash/clash #授予权限 +chmod 777 /etc/init.d/clash #授予权限 +service clash enable #启用clash开机启动 +service clash start #启动clash服务 +sed -i "8iport=5335" /etc/dnsmasq.conf #修改dnsmasq监听端口为5335 +service dnsmasq restart #重启dnsmasq服务(报错“cp: can't stat '/etc/dnsmasq.d/*'……”可无视) +``` +```sh +#启用clash透明网关 +service clash enable #启用clash开机启动 +service clash start #启动clash服务 +sed -i "8iport=5335" /etc/dnsmasq.conf #修改dnsmasq监听端口为5335 +service dnsmasq restart #重启dnsmasq服务(报错“cp: can't stat '/etc/dnsmasq.d/*'……”可无视) +``` +```sh +#停止clash透明网关 +service clash disable #禁用clash开机启动 +service clash stop #停止clash服务 +sed -i '/port=5335/d' /etc/dnsmasq.conf #重置dnsmasq监听端口为默认值(port:53) +service dnsmasq restart #重启dnsmasq服务(报错“cp: can't stat '/etc/dnsmasq.d/*'……”可无视,不放心可重启系统) +``` +```sh +#卸载clash相关文件(卸载前请先配合“停止clash透明网关”使用) +rm -rf /etc/clash #删除clash文件夹及文件 +rm /etc/init.d/clash #删除clash开机启动文件 +``` + +已知问题: +-- +a,部分软件不会经过clash,例如telegram,可以通过设置软件内置sock5或http代理解决
+b,tun模式的CPU耗用较高,速度不是很理想,而且会影响全局流量(所有tcp和udp流量都会经过tun虚拟网卡和clash),ax1800实测带宽在60M左右。不过p2p流量通常不会进入tun,故下载速度应该不受影响
+c,由于使用了clash的fake-ip模式,部分网站可能会出现验证错误,待确认
+d,由于变相禁用了dnsmasq的dns解析服务且clash不支持内置hosts,miwifi.com或www.miwifi.com 无法打开路由器管理界面,只能使用192.168.31.1进入(app不受影响)
+e,由于同样使用了tun模式虚拟网卡,clash服务可能会和小米路由器内置的tx网游加速器冲突,请谨慎同时使用
+f,不支持订阅,由于clash本身不支持对v2ray,ss,trojan等协议的订阅,所以订阅只能通过更新clash的配置文件config.yaml来进行,有条件的可以自行写更新脚本
+g,不支持ssr,clash官方不支持ssr,而支持ssr的clashr又不支持tun……
+h,全局模式代理无效,原因不明,同样的配置文件在pc端或者安卓上都可以使用全局模式,怀疑是tun模式的bug + +参考: +-- +https://lancellc.gitbook.io/clash/start-clash/clash-tun-mode
+https://comzyh.gitbook.io/clash/
+https://h-cheung.gitlab.io/post/使用_clash_和路由表实现透明代理/
+ diff --git a/clash config/config.yaml b/clash config/config.yaml index 6af96c3..61b83bc 100644 --- a/clash config/config.yaml +++ b/clash config/config.yaml @@ -11,7 +11,7 @@ mode: Rule # 设置日志输出级别 silent / info / warning / error / debug 越高越倾向于调试 log-level: info # clash 的 RESTful API 网页调试端口 -external-controller: 127.0.0.1:9090 +external-controller: 0.0.0.0:9090 # RESTful API 的口令 (可选) # secret: "" # external-ui: clash-dashboard @@ -102,12 +102,12 @@ proxies: #代理节点配置,参考下列规则修改 server: 9.99.99.99 port: 6666 cipher: chacha20-ietf-poly1305 - password: "123" + password: "asdf1234" #udp: true - name: "Trojan" type: trojan - server: tyu.abc.xyz + server: 123.abc.xyz port: 443 password: asdf1234 skip-cert-verify: true @@ -1592,4 +1592,4 @@ rules: - IP-CIDR,119.28.28.28/32,DIRECT,no-resolve # GeoIP China - GEOIP,CN,DIRECT -- MATCH,PROXY \ No newline at end of file +- MATCH,PROXY