Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

负载均衡 2中 直连规则优先级问题 #50

Open
teraStars opened this issue Aug 25, 2019 · 3 comments
Open

负载均衡 2中 直连规则优先级问题 #50

teraStars opened this issue Aug 25, 2019 · 3 comments
Labels
enhancement New feature or request pull request wanted no obvious way to fix

Comments

@teraStars
Copy link

teraStars commented Aug 25, 2019

当route用的是IPIfNonMatch时,当最后再加上这么一条

 {
        "type": "field",
        "network": "tcp,udp",
        "balancerTag": "b1"
}

会导致第一条route不再运行,因为最后那条肯定已经匹配上了。

{
        "type": "field",
        "outboundTag": "direct",
        "ip": [
          "geoip:private",
          "geoip:cn"
        ]
},

所以当出现虽然是国内网站,但因为域名没有加入geosite:cn,于是不再匹配geoip:cn这条,于是直接就走balancer了,而不是走direct。

@nicholascw nicholascw added unconfirmed Waiting investigation bug Something isn't working and removed unconfirmed Waiting investigation labels Sep 28, 2019
@nicholascw
Copy link
Contributor

nicholascw commented Sep 28, 2019

是实测结果吗?官方文档这部分内容似乎描述确实比较模糊。

"IPIfNonMatch": 当域名没有匹配任何规则时,将域名解析成 IP(A 记录或 AAAA 记录)再次进行匹配;当一个域名有多个 A 记录时,会尝试匹配所有的 A 记录,直到其中一个与某个规则匹配为止;
解析后的 IP 仅在路由选择时起作用,转发的数据包中依然使用原始域名;

对应一个数组,数组中每个元素是一个规则。对于每一个连接,路由将根据这些规则依次进行判断,当一个规则生效时,即将这个连接转发至它所指定的outboundTag(或balancerTag,V2Ray 4.4+)。当没有匹配到任何规则时,流量默认由主出站协议发出。

http://www.v2fly.org/chapter_02/03_routing.html#ruleobject

根据官方文档描述如果,当前白话文教程中的配置文件应该仍然能保证解析到 goip:cn 中的IP的域名走direct outbound。

DomainStrategy 描述的应当是每个 RuleObject 内的匹配流程,所以这里的配置文件中,首先应该在只有 geoip:cn 的RuleObject 中寻找域名规则(此处没有),于是立即解析为IP开始判断,所以并不应该出现遗漏。只是这样看起来geosite在其之后确有不合理之处(判断效率),可以将两者调换顺序或改为IPOnDemand。

@nicholascw nicholascw added unconfirmed Waiting investigation enhancement New feature or request and removed bug Something isn't working labels Sep 28, 2019
@lizezhigrass
Copy link

这个问题如此有意思,所以超级懒的我还是抽时间来做了一个测试。测试方法为选择一个不存在的域名route.try 并使用dnsmasq 将此域名解析到兰州理工大学的主页IP。因此,此域名一定不在geosite:cn内,但解析得的IP一定在geoip:cn内,观察请求的最终发出线路可对楼主的说法进行验证。当然,测试时不要忘记将domainStrategy配置为IPIfNonMatch。

测试表明,路由如何选择与是否是透明代理、是否开启sniffing都有关系。
情况一:浏览器配置socks5(非透明代理),关闭sniffing,路由选择负载均衡线路发出请求;
情况二:浏览器配置socks5(非透明代理),开启sniffing,路由选择负载均衡线路发出请求;
情况三:透明代理,关闭sniffing,因IP包已经包含了目的IP地址,路由根据目的IP地址匹配到了geoip:cn,选择国内直连发出请求;
情况四:透明代理,开启sniffing,路由无视IP包目的IP地址,选择负载均衡线路发出请求。

因此,想要同时保留geoip:cn国内直连和负载均衡的办法是domainStrategy配置为IPOnDemand。

@ToutyRater
Copy link
Collaborator

这确实是个问题,这是因为 IPIfNonMatch 的机制是在先使用域名对所有规则进行匹配,如果没有可以匹配的规则,那么才会转为 ip 再进行一次规则匹配。任何进入 V2Ray 的流量都符合 "network": "tcp,udp",所以会直接按照 "network": "tcp,udp" 的规则转发,而不会再转为 IP。

@nicholascw nicholascw added pull request wanted no obvious way to fix and removed unconfirmed Waiting investigation labels Nov 21, 2019
@nicholascw nicholascw changed the title 负载均衡 2中举的例子有问题。 负载均衡 2中 直连规则优先级问题 Nov 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pull request wanted no obvious way to fix
Projects
None yet
Development

No branches or pull requests

4 participants