mellow-io / mellow

Mellow is a rule-based global transparent proxy client for Windows, macOS and Linux. Also a Proxifier alternative.
3.55k stars 470 forks source link

Mellow DNS解析性能问题 #126

Closed laggardkernel closed 4 years ago

laggardkernel commented 4 years ago

V2Ray 4.22.0+ 对 ServerObject 加入了 expectIPs 项,可以对 DNS 服务器返回的地址进行过滤。应该可以基于 IP 地理位置去污染。

{
  "address": "1.2.3.4",
  "port": 5353,
  "domains": [
    "domain:v2ray.com"
  ],
  "expectIPs": [
    "geoip:cn"
  ]
}

expectIPs from V2ray Doc


更新:问题根源在于默认的 geosite:geolocation-!cn 规则过大。我个人认为纯基于域名分流防污染本身就是个烂方案:规则小了命不中被污染域名,规则大了匹配耗时。

本次测试域名主要有 google.com, youtube.com, github.com, kindleren.com. DNS 规则

[DnsRule]
DOMAIN-KEYWORD, geosite:geolocation-!cn, Remote
DOMAIN-SUFFIX, kindleren.com, Remote

其中主要受影响域名为 kindleren.com,因为不被包含在 geosite:geolocation-!cn 规则中,需要等待前边所有规则匹配完成后才能匹配到它。也正是这条规则,让我感受到了首次打开等待几秒。

将第一条规则 DOMAIN-KEYWORD 改为 DOMAIN-KEYWORD 后略有好转,kindleren.com 首次 DNS 解析时间略有好转。

结论:

纯域名的DNS防污染问题不能让作者背锅,这是的 v2ray 团队的选择,且实现到了 v2ray-core 中。(Mellow基于v2ray-core)

目前还有一定疑问,如果不使用 dns-hijack 而是自己进行DNS无污染解析,对于代理规则匹配有没有影响?


环境

DNS 相关配置

[Dns]
; hijack = dns endpoint tag
hijack = Dns-Out
; clientIp = xxx.xxx.xxx.xxx

[DnsServer]
; address, port, tag
localhost
114.114.114.114
8.8.8.8, 53, Remote

[DnsRule]
DOMAIN-KEYWORD, geosite:geolocation-!cn, Remote

本地DNS为ISP分配DNS,"Domain Sniffing" 开启,首次访问一个被污染网站时较慢。

后改用本地 dnsmasq + chinadns + stubby 转发DNS防污染,关闭 "hijack",设置系统DNS 127.0.0.1,不再有首次请求延迟。(对比时已经重启了dnsmasq清理了缓存。)

可以感知到 Mellow DNS 解析相对于 dnsmasq 这一套有秒级别的延迟。

(日志中好像没有DNS解析相关信息,如需提供进一步的详细报告,请在回复中说明相应指示。)

mzxwt commented 4 years ago

dnsmasq貌似可以缓存吧?不知道Mellow有没有。另外,udp是否经过代理?我是小白,特来请教。

laggardkernel commented 4 years ago

@mzxwt DNS可以缓存,我也强调了是首次解析一个域名耗时非常严重,解析个域名耗时都是秒级别的了。Mellow支持代理UDP。

个人觉得Mellow短板在于DNS无污染方案完全基于域名,没有ChinaDNS那种并发查询之后基于IP位置再判断的机制。基于IP段判断的命中率应该比纯基于域名高(不仅要写很多域名,还不能保证配置中域名涵盖了所有被污染站点)。

Azero-NG commented 4 years ago

环境

同发现首次解析一个域名耗时非常严重

Azero-NG commented 4 years ago

附上配置

{
    "dns": {
      "servers": [
        "8.8.8.8",
        {
          "address": "114.114.114.114",
          "port": 53,
          "domains": [
            "geosite:cn"
          ]
        },
        "localhost"
      ]
    },
    "outbounds": [
      {
        "protocol": "vmess",
        "tag": "Proxy-1",
      },
      {
        "protocol": "freedom",
        "tag": "Direct",
        "settings": {
          "domainStrategy": "UseIP"
        }
      },
      {
        "protocol": "dns",
        "tag": "Dns-Out",
        "settings": {}
      }
    ],
    "routing": {
      "rules": [
        {
          "type": "field",
          "outboundTag": "Dns-Out",
          "inboundTag": [
            "tun2socks"
          ],
          "network": "udp",
          "port": 53
        },
        {
          "type": "field",
          "outboundTag": "Direct",
          "domain": [
            "geosite:cn"
          ]
        },
        {
          "type": "field",
          "outboundTag": "Direct",
          "ip": [
            "geoip:cn",
            "geoip:private"
          ]
        },
        {
          "type": "field",
          "outboundTag": "Proxy-1",
          "network": "tcp,udp"
        }
      ]
    }
  }
Azero-NG commented 4 years ago

本来想用国内红鱼doh服务的,配置改成这样,v2ray官方文档是支持的,但是mellow报错,应该是不支持

"dns": {
    "servers": [
"https://dns.rubyfish.cn/dns-query",
      {
        "address": "localhost",
        "port": 5353
      },
      {
        "address": "114.114.114.114",
        "port": 53,
        "domains": [
          "geosite:cn"
        ]
      },
      "localhost"
    ]
  }
Azero-NG commented 4 years ago

最后只好换成dnscrypt doh转dns搞定了

"dns": {
    "servers": [
      {
        "address": "localhost",
        "port": 5353
      },
      {
        "address": "114.114.114.114",
        "port": 53,
        "domains": [
          "geosite:cn"
        ]
      },
      "localhost"
    ]
  }
laggardkernel commented 4 years ago

详细更新将更在1楼中。

经测试,自己定义的未在列表中的域名(kindleren.com)匹配最慢。DOMAIN-KEYWORD, geosite:geolocation-!cn, Remote 改为 DOMAIN-SUFFIX 后略有好转。基本结论,列表太大了,使用 DOMAIN-KEYWORD 匹配完所有 geosite:geolocation-!cn 时间更长。

github-actions[bot] commented 4 years ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days