dns配置中的servers好像不是顺序匹配造成了一些逻辑bug #908
Replies: 8 comments 9 replies
-
try dns skipFallback |
Beta Was this translation helpful? Give feedback.
-
Can’t tell much without seeing your config, but it’s clearly not a bug. You probably put IP rules before domain rules, while using |
Beta Was this translation helpful? Give feedback.
-
所使用的配置示意:
routing(translate.google.cn)>geosite:cn>outboundTag(direct) |
Beta Was this translation helpful? Give feedback.
-
路由规则确实会有少量冲突,介意的话,请自行为那些冲突的规则显式定制路由和 DNS。另外,建议境外 DNS 放在境内 DNS 的上面/前面。 |
Beta Was this translation helpful? Give feedback.
-
在你这个案例中,只要把 |
Beta Was this translation helpful? Give feedback.
-
附上相应的Debug日志信息 curl -x socks5://127.0.0.1:1080 translate.google.cn 2021/04/16 18:51:26 [Warning] V2Ray 4.37.3 started |
Beta Was this translation helpful? Give feedback.
-
找到了,不是 bug,是个 feature,应该是故意为之。 https://github.com/v2fly/v2ray-core/blob/1e222425b6/common/strmatcher/domain_matcher.go#L90-L96 由于 要解决你这个情况,在 DNS 部分这样配置即可( "dns":{
"servers":[
{ //中国主流网站和中国域名优先使用阿里的 DNS
"address":"223.5.5.5",
"port":53,
"domains":[
"geosite:cn",
"full:translate.google.cn",
"ntp.org"
]
},
{ //境外主流网站域名优先使用 Google 的 DNS
"address":"8.8.8.8",
"port":53,
"domains":[
"geosite:geolocation-!cn"
]
}
]
},
|
Beta Was this translation helpful? Give feedback.
-
目前来看最好的路由规则,应该是白名单直连,黑名单直接代理,未知域名使用内置DNS解析成IP再做判断。 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
一切的起因是 translate.google.cn
这虽然是个谷歌域名,但是却是cn结尾,实际上谷歌翻译可以在中国直连访问。
域名规则文件的包含关系中,geosite:cn和geolocation-!cn出现了交集。
geosite:cn>tld-cn>.cn
geolocation-!cn>tld-!cn>google>.google.cn
到目前为止好像和v2ray没有关系,是域名规则文件的锅,但后边就不是了。
routing配置中,rules的匹配是按照集合顺序匹配的。
如果geosite:cn(直连)在前,translate.google.cn会被路由判定为直连。
但是在outbounds中,如果直连配置了"domainStrategy":"UseIP",v2ray就会去dns调取服务器并解析IP地址
通过看debug日志,发现dns的servers结果并不按照集合顺序排列。
translate.google.cn同时符合geosite:cn(在前)与geolocation-!cn(在后),结果dns匹配结果列表反而8.8.8.8在前
进而通过8.8.8.8拿到了translate.google.cn的境外IP,最终造成v2ray通过直连路径连接境外IP无法连通。
如果将v2ray的内置dns服务器作为透明代理的dns服务器,也会造成类似问题,而且无法在v2ray中解决
浏览器访问translate.google.cn的DNS请求发送至路由,转发至v2ray的内置dns服务器,得到境外IP
浏览器的HTTP连接中含有域名信息,被v2ray嗅探之后,路由会选择直连路径(还是因为geosite:cn)
此时无论直连配置的domainStrategy如何配置,都会拿到v2ray之前缓存的境外IP,然后凉凉
归根结底是因为routing是顺序匹配,而dns的servers结果乱序,不清楚机理,因而顺序不可靠
日志中,有时候一条geosite条件能出现多个匹配的dns项,可能域名在规则文件中出现了多次
希望能将dns的servers结果也改为顺序匹配
另外也可以考虑将dns的"clientIp"升级一下,做成一个嗅探功能
用一个中国IP作为clientIp发给服务器,如果返回的是境外IP,则代表此网站没有中国节点,不可直连
之后不带clientIp再次发送dns请求,获得正确位置的境外IP(一般是VPS的IP位置附近)
Beta Was this translation helpful? Give feedback.
All reactions