Files
ShellCrash/README.md
2020-07-08 20:28:04 +08:00

77 lines
4.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# clash_tun-for-Miwifi
在小米AX3600/AX1800/AX5等路由器上使用clash_tun模式做透明代理
=====
PS
--
小米路由内置的openwrt默认阉割了对tproxy的支持所以使用redir模式做透明代理时无法转发udp流量只能采用tun模式转发udp流量<br>
tun模式对udp的转发支持非常好而且延迟非常低小米官方内置的tx网游加速器其实就是使用的tun模式<br>
支持ss,v2ray,trojan但不支持ssr也不支持订阅<br>
clash对tun模式的官方文档内容不是很完善折腾了好几天也没搞懂怎么使用真实ip模式进行透明代理故只能采用较为简单但速度更快的fake-ip模式<br>
fake-ip模式在数据向dns查询时默认会返回例如198.18.0.x这样的虚拟ip地址故部分必须验证真实ip地址的网站或app可能会受影响<br>
系统默认的dnsmasq非常霸道会强行劫持所有53端口流量所以必须修改dnsmasq的默认端口以让流量经过clash内置dns服务<br>
fake-ip+tun模式的透明代理方式可能适用于大部分采用openwrt内核的路由器或者软路由有需求的可以自行斟酌使用<br>
使用依赖:
--
请确认路由器或设备已经开启ssh并获取root权限小米AX系列可参考https://www.right.com.cn/forum/thread-4032490-1-1.html<br>
ssh工具或telent工具例如puttybitvise<br>
scp工具如winscp内置了putty注意小米AX系列没有内置sftp服务而是内置了scp服务<br>
使用方式:
--
下载clash.zip https://github.com/juewuy/clash_tun-for-Miwifi/raw/master/clash.zip 并解压<br>
根据自己需求参考备注修改config.yaml配置文件`重要!!!`<br>
也可以自行下载或更新clash-tun模式核心文件并重命名 https://github.com/Dreamacro/clash/releases/tag/premium 小米AX系列都是armv7架构其他路由器请自查<br>
将clash文件夹以及内部4个文件通过winSCP上传到路由器/etc文件夹下<br>
在ssh中用root用户执行下列相应命令即可<br>
启用后可以通过 http://clash.razord.top 管理clash内置规则<br>
启动后无需其他设置即可连接代理服务器<br>
也可以自行配置http代理端口7890或者sock5代理端口7891速度比tun模式更快但是相对延迟可能较高<br>
```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 's|port=53|port=5335|' /etc/dnsmasq.conf #修改dnsmasq监听端口
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代理解决<br>
btun模式的CPU耗用较高速度不是很理想而且会影响全局流量所有tcp和udp流量都会经过tun虚拟网卡和clashax1800实测带宽在60M左右不过p2p流量通常不会进入tun故速度不受影响<br>
c使用了clash的fake-ip模式部分网站可能会出现验证错误待确认<br>
d由于变相禁用的dnsmasq的dns解析服务miwifi.com或www.miwifi.com 无法打开路由器管理界面只能使用192.168.31.1进入app不受影响<br>
e可能会和小米路由器内置的网游加速器冲突请谨慎同时使用<br>
f不支持订阅由于clash本身不支持对v2raysstrojan等协议的订阅所以订阅只能通过更新config.yaml来进行有条件的可以自行写脚本<br>
g不支持ssrclash官方不支持ssr而支持ssr的clashr又不支持tunso……<br>
参考:
--
https://lancellc.gitbook.io/clash/start-clash/clash-tun-mode<br>
https://comzyh.gitbook.io/clash/<br>
https://h-cheung.gitlab.io/post/使用_clash_和路由表实现透明代理/<br>