vernesong / OpenClash

A Clash Client For OpenWrt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] Fake IP模式下的NTP问题

WFANG12719 opened this issue · comments

Verify Steps

  • Tracker 我已经在 Issue Tracker 中找过我要提出的问题
  • Branch 我知道 OpenClash 的 Dev 分支切换开关位于插件设置-版本更新中,或者我会手动下载并安装 Dev 分支的 OpenClash
  • Latest 我已经使用最新 Dev 版本测试过,问题依旧存在
  • Relevant 我知道 OpenClash 与 内核(Core)、控制面板(Dashboard)、在线订阅转换(Subconverter)等项目之间无直接关系,仅相互调用
  • Definite 这确实是 OpenClash 出现的问题
  • Contributors 我有能力协助 OpenClash 开发并解决此问题
  • Meaningless 我提交的是无意义的催促更新或修复请求

OpenClash Version

v0.46.001-beta

Bug on Environment

Lean

OpenWrt Version

OpenWrt R23.2.14 by lean & lienol

Bug on Platform

Linux-arm64

Describe the Bug

仔细看过#1133 的描述和解决问题方法了,但在我的配置上就是不生效,把常用的ntp 服务器都加入了fake-ip-filter里还是不起作用。网络里的Windows电脑,苹果手机,安卓手机,苹果笔记本电脑,Linux服务器的时间都不正确,慢60-90秒。在客户端运行ntpd 或ntpclient命令都失败,提示ntp服务器不存在或不可到达。
和IPv6的设置无关,试过了把IPv6相关设置都禁止,结果也一样。

To Reproduce

旁路由,fake-ip增强模式,各种客户端本地时间不正确,无法和因特网NTP 服务器例如 ntp.tencent.com, ntp.aliyun.com, time.apple.com, time.windows.com等同步时间。

OpenClash Log

见附件

OpenClash Config

No response

Expected Behavior

还请哪位告知在fake ip下如何配置,使客户端可以正确接受ntp服务器调整时间。

Additional Context

openclash_cfg.txt

你好,你UDP通吗?

自身可以,客户端不行,那udp还是有问题吧
要不把udp代理上试试?或者换个模式?
tun被人说有bug的,试下这位的方法https://github.com/vernesong/OpenClash/issues/3762

openwrt系统的时间同步里有一个将自身作为ntp服务器,在找问题或解决方法的时候暂且打开应个急?

感谢vernesong本尊亲自出马,在上面防火墙配置里勾上了“IP动态伪装”,把软路由重新启动了,还是不起作用。

我也遇到这问题,以下是我的解决办法,供参考:
1、勾选Fake-IP 持久化
2、勾选Fake-IP-Filter
3、勾选主机,如下图,将你需要的ntp 域名和对应的ip写进去,作用类似/etc/hosts
image

谢谢兄台。可惜,结果还是不行。我都不知道哪里有问题了。 下面前面两个NTP服务器是两台局域网的机器用做NTP服务器就可以,其它互联网上的都不行。

Checking current status of NTP service with ntpq -p
remote refid st t when poll reach delay offset jitter

+R-N1-1 17.253.84.125 2 u 105 128 377 3.415 -26.221 21.029
*R-N1-2 17.253.116.253 2 u 109 128 377 3.660 +16.784 4.907
106.55.184.199 .XFAC. 16 u - 128 0 0.000 +0.000 0.000
203.107.6.88 .XFAC. 16 u - 128 0 0.000 +0.000 0.000
17.253.84.253 .XFAC. 16 u - 128 0 0.000 +0.000 0.000
114.118.7.161 .XFAC. 16 u - 128 0 0.000 +0.000 0.000
139.199.215.251 .XFAC. 16 u - 128 0 0.000 +0.000 0.000
223.113.103.191 .XFAC. 16 u - 128 0 0.000 +0.000 0.000
20.189.79.72 .XFAC. 16 u - 128 0 0.000 +0.000 0.000
132.163.96.1 .XFAC. 16 u - 128 0 0.000 +0.000 0.000
(Auto-Refresh every 10s --- CTRL+C to Cancel)

正常的ntpq 查询应该如下列输出:

Checking current status of NTP service with ntpq -p
remote refid st t when poll reach delay offset jitter

R-N1-1 17.253.84.125 2 u 35 64 1 5.132 +6.882 2.472
R-N1-2 17.253.116.253 2 u 36 64 1 4.533 -0.247 1.046
106.55.184.199 100.122.36.196 2 u 14 64 1 12.028 +35.091 0.460
203.107.6.88 100.107.25.114 2 u 28 128 1 50.518 +38.996 0.403
hkhkg1-ntp-002. .XFAC. 16 u - 128 0 0.000 +0.000 0.000
114.118.7.161 .XFAC. 16 u - 128 0 0.000 +0.000 0.000
*139.199.215.251 100.122.36.196 2 u 57 128 1 12.756 +36.684 12.643
+223.113.103.191 10.137.53.7 3 u 37 64 1 38.046 +35.298 4.185
-20.189.79.72 25.66.230.4 3 u 30 64 1 102.960 +39.448 35.703
-time-a-b.nist.g .NIST. 1 u 39 128 1 222.514 +22.897 20.951
(Auto-Refresh every 10s --- CTRL+C to Cancel)

感谢vernesong本尊亲自出马,在上面防火墙配置里勾上了“IP动态伪装”,把软路由重新启动了,还是不起作用。

我的办法很简单,打开软路由上的ntp server,在防火墙上劫持udp port 123的流量到软路由本身,前端不管哪一种客户端都能同步,这样就不需要客户端一个个更改设置

下了两条命令在软路由上,看看:
iptables -t nat -A PREROUTING -i br-lan -p udp --dport 123 -j DNAT --to-destination 192.168.192.129:123
iptables -t nat -A POSTROUTING -o br-lan -j MASQUERADE

下了两条命令在软路由上,看看: iptables -t nat -A PREROUTING -i br-lan -p udp --dport 123 -j DNAT --to-destination 192.168.192.129:123 iptables -t nat -A POSTROUTING -o br-lan -j MASQUERADE

主要是上面那条起作用
iptables -t nat -I PREROUTING -i $lan -p udp --dport 123 -j REDIRECT --to-ports 123 ($lan是我定义的本机IP变量)
直接跳转本机123端口就行了,不需要DNAT(这个当然也可以的,作用相同)
如果你的防火墙挡了udp协议,记得在相关的chain里加上Accept的命令

感谢。这个nat所有 UDP123流量的起作用。
以下是在Windows上运行 ntpq的结果:
C:>ntpq -pw
remote refid st t when poll reach delay offset jitter

+203.107.6.88 100.107.25.114 2 u 17 64 377 76.233 +3.414 10.224
-hkhkg1-ntp-002.aaplimg.com
63.123.5.208 2 u 193 64 374 45.402 -2.598 24.519
+114.118.7.161 .OLEG. 1 u 69 64 16 74.547 +0.469 38.596
-162.159.200.123 (time.cloudflare.com)
10.209.8.8 3 u 2 64 377 183.657 -5.760 32.151
*2001:da8:9000::130
.PTP. 1 u 63 64 377 83.443 +0.192 4.808
+20.189.79.72 25.66.230.5 3 u 23 64 377 123.951 +4.897 34.943
time-e-b.nist.gov
.STEP. 16 u - 128 0 0.000 +0.000 0.000
+106.55.184.199 100.122.36.196 2 u 2 64 377 44.535 -2.834 2.365

另外在DHCP里加上option 42 为所有客户端分发本地NTP服务器(openwrt机器可以做NTP服务器)

临时解决方法(workaroud):估计得临时很久。。。
1)将openwrt设置为NTP服务端,openwrt机器定时与互联网知名NTP服务器同步时间。openwrt机器对自己内网的机器提供NTP服务。
2)在openwrt机器上添加iptables (具体见上)将本地子网内的NTP流量指向openwrt服务器。在本地DHCP服务器里添加option 42为所有客户端提供本地NTP服务器IP地址(大部分Linux和安卓的设备DHCP请求包中会包含请求NTP服务器地址)

看下控制面板日志,这些ntp服务流量是怎么走的