vernesong / OpenClash

A Clash Client For OpenWrt
MIT License
17.1k stars 3.13k forks source link

[help wanted] fake-ip tun 模式下 0.42.03 无法访问 telegram #1286

Closed kmahyyg closed 3 years ago

kmahyyg commented 3 years ago

tun 模式,0.42.02 正常,看起来像是tg这种直接用ip访问的失效了。其他的都可以正常使用。

vernesong commented 3 years ago

控制面板访问日志

kmahyyg commented 3 years ago

问题个人猜测应该在 tun 模块上,我尝试降级了 clash_tun 和 openclash 并针对两者的版本进行排列组合测试发现,问题仅在 tun with fake-ip 模式时出现,单纯的 fake-IP 不存在此问题。路由器是 gl-inet gl-xe300,未使用 redir-host 进行测试。请求协助进一步确认问题,感谢您的回复。

kmahyyg commented 3 years ago

能否请求占用您一点宝贵的时间请求协助定位问题:

备注:已通过 sysctl.conf 从内核参数层面禁用了 ipv6 支持,应当不存在 ipv6 相关的问题。 IPv6 ULA 前缀已经清空,DHCPv6 已经禁用。所有日志均已脱敏。

Openclash 面板日志

Clash Dashboard WebUI 日志

从 clash dashboard 拷贝的连接日志如下:(开启 chrome 和 telegram)

tun模式下 conn 界面截图:(可以看到没有以 ip 为目的地的连接) debug_tun

telegram的日志: telegram-tun-log.txt

fakeip enh. 模式下的截图: debug_notun

telegram 的日志: telegram-notun-log.txt

kmahyyg commented 3 years ago

在 fake-ip tun 模式下, clash dashboard 中无法看到任何目的地为纯 ip 的连接信息,此时连接模式显示为 tun。在 fake-ip(enhanced) 下可以看到,此时连接模式显示为 redir。

kmod-tun 存在。这个出问题的是我的随身路由,为 gl-inet 官方的 openwrt 19.x 固件;家里的 snapshot(自行使用 lean 源码编译)的固件使用 tun 模式不存在任何问题,因此猜测为 系统tun模块的问题。

kmahyyg commented 3 years ago

update: 编辑了之前的 issue comment 以提供更详尽的日志和截图协助定位问题。

kmahyyg commented 3 years ago

另:自定义 dns (&fallback) 功能没有生效。我在 luci 中的 openclash dns 配置与日志中的 clash 配置文件中所写的 dns 配置完全不符。

image

xuhuanxxx commented 3 years ago

这个好像是系统和iptables的问题,之前我在官方源那边开过一个讨论 https://github.com/Dreamacro/clash/discussions/1251 ,解决了问题到是也没找到原因。 后来又用 clash-premium-installer 测试在 Fedora 33 x86-64、Ubuntu 20.10 x86-64、Debian 9 arm64三个系统上跑clash的fake ip tun模式,结果就是debian系的两个正常,Fedora即使是tcpdump都看不到纯IP地址的请求。ShellClash 更是在3个测试的系统上都不能正常处理纯IP地址的请求。

不过这些问题再设置一下iptables就好了。

#!/bin/bash

ip rule del fwmark 100 table 100  2> /dev/null
ip route del default dev lo table 100 2> /dev/null
ip route flush table 100
iptables -t raw -F
iptables -t raw -X
iptables -t mangle -F clash 2> /dev/null
iptables -t mangle -X clash 2> /dev/null
iptables -D FORWARD -o utun -j ACCEPT 2> /dev/null

# 创建 Clash Chain
iptables -t mangle -N clash

# 放行内网内部数据
iptables -t mangle -A clash -d 0.0.0.0/8 -j RETURN
iptables -t mangle -A clash -d 10.0.0.0/8 -j RETURN
iptables -t mangle -A clash -d 127.0.0.0/8 -j RETURN
iptables -t mangle -A clash -d 169.254.0.0/16 -j RETURN
iptables -t mangle -A clash -d 172.16.0.0/12 -j RETURN
iptables -t mangle -A clash -d 192.168.0.0/16 -j RETURN
iptables -t mangle -A clash -d 224.0.0.0/4 -j RETURN
iptables -t mangle -A clash -d 240.0.0.0/4 -j RETURN

# 限制高目标端口的流量
iptables -t mangle -A PREROUTING -p udp -m udp --dport 4096:65535 -j RETURN
iptables -t mangle -A PREROUTING -p tcp -m tcp --dport 8192:65535 -j RETURN

# 其他数据打上标记
iptables -t mangle -A clash -j MARK --set-xmark 100

# 给转发流量打上fwmark
iptables -t mangle -A PREROUTING -j clash
# 放行root用户数据避免回环
iptables -t mangle -A OUTPUT -m owner --uid-owner 0 -j RETURN

# utun添加策略路由表
ip route add default dev utun table 100
# 标记为100的包由策略路由表100处理
ip rule add fwmark 100 lookup 100

exec "$@"
kmahyyg commented 3 years ago

@xuhuanxxx 我记得这些指令 openclash 都有设,我回去核实一下,感谢。

kmahyyg commented 3 years ago

经查,路由存在默认路由没有设置的问题。进一步查,发现:官方固件会在后台自动拉起 mwan3 造成冲突,移除mwan3即恢复... CNMD GLinet.....