V2ray-core: 米家服务访问问题 [Warning] v2ray.com/core/app/router: resolve ip for Mijia Cloud > v2ray.com/core/app/dns: invalid domain name

Created on 1 Jul 2020  ·  6Comments  ·  Source: v2ray/v2ray-core

提交 Issue 之前请先阅读 Issue 指引,然后回答下面的问题,谢谢。
除非特殊情况,请完整填写所有问题。不按模板发的 issue 将直接被关闭。
如果你遇到的问题不是 V2Ray 的 bug,比如你不清楚要如何配置,请使用Discussion进行讨论。

1) 你正在使用哪个版本的 V2Ray?(如果服务器和客户端使用了不同版本,请注明)
V2Ray 4.25.1 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.14.4 linux/arm)
2) 你的使用场景是什么?比如使用 Chrome 通过 Socks/VMess 代理观看 YouTube 视频。
使用v2ray作为透明代理,参考配置 https://guide.v2fly.org/app/tproxy.html

3) 你看到的不正常的现象是什么?(请描述具体现象,比如访问超时,TLS 证书错误等)
可以访问Google等境外网络,但米家服务无法访问,出现 [Warning] v2ray.com/core/app/router: resolve ip for Mijia Cloud > v2ray.com/core/app/dns: invalid domain name

4) 你期待看到的正确表现是怎样的?
期望米家的服务可以通过代理访问。用的歌华有线的宽带,本身访问可以用米家的服务,但米家里的固件升级都用不了(用手机热点就可以),不知道原因。希望米家这部分也可以通过代理访问

5) 请附上你的配置(提交 Issue 前请隐藏服务器端IP地址)。

客户端配置:

{
    "log": {
                "access": "/var/log/v2ray/access.log",
                "error": "/var/log/v2ray/error.log",
        "loglevel": "warning"
      },

  "inbounds": [
    {
      "tag":"transparent",
      "port": 12345,
      "protocol": "dokodemo-door",
      "settings": {
        "network": "tcp,udp",
        "followRedirect": true
      },
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ]
      },
      "streamSettings": {
        "sockopt": {
          "tproxy": "tproxy" // 透明代理使用 TPROXY 方式
        }
      }
    }
  ],
  "outbounds": [
    {
      "tag": "proxy",
      "protocol": "vmess", // 代理服务器cf
      "settings": {
        "vnext": [
            {
                "address": "",
                "port": 443,
                "users": [
                  {
                    "id": "",
                    "alterId": 64
                  }
                ]
            }
        ]
      },
      "streamSettings": {
        "network": "ws",
        "security": "tls",
        "tlsSettings": {
          "allowInsecure": false
        },
        "wsSettings": {
          "connectionReuse": true,
          "path": "/logt"
        },
        "sockopt": {
            "mark": 255
          }
      },
      "mux": {
        "enabled": true
      }
    },

    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {
        "domainStrategy": "UseIP"
      },
      "streamSettings": {
        "sockopt": {
          "mark": 255
        }
      }
    },
    {
      "tag": "block",
      "protocol": "blackhole",
      "settings": {
        "response": {
          "type": "http"
        }
      }
    },
    {
      "tag": "dns-out",
      "protocol": "dns",
      "streamSettings": {
        "sockopt": {
          "mark": 255
        }
      }
    }
  ],
  "dns": {
    "servers": [

      {
        "address": "223.6.6.6",
        "port": 53,
        "domains": [
          "geosite:cn",
          "ntp.org",   // NTP 服务器
        ]
      },
        {
          "address": "8.8.8.8",
          "port": 53,
          "domains": [
            "geosite:speedtest",
            "ext:h2y.dat:gfw"
          ]
        },
        "223.6.6.6"
    ]
  },
  "routing": {
    "domainStrategy": "IPOnDemand",
    "rules": [
      { // BT 流量直连
        "type": "field",
        "protocol":["bittorrent"],
        "outboundTag": "direct"
      },
      { // 劫持 53 端口 UDP 流量,使用 V2Ray 的 DNS
        "type": "field",
        "inboundTag": [
          "transparent"
        ],
        "port": 53,
        "network": "udp",
        "outboundTag": "dns-out"
      },
      { // 直连 123 端口 UDP 流量(NTP 协议)
        "type": "field",
        "inboundTag": [
          "transparent"
        ],
        "port": 123,
        "network": "udp",
        "outboundTag": "direct"
      },
      {
        "type": "field",
        "ip": [
          // 设置 DNS 配置中的国内 DNS 服务器地址直连,以达到 DNS 分流目的
          "223.5.5.5",
          "223.6.6.6",
          "114.114.114.114"
        ],
        "outboundTag": "direct"
      },
      {
        "type": "field",
        "inboundTag": ["proxy-all"],
        "outboundTag": "proxy"
      },
      {
        "type": "field",
        "ip": [
          // 设置 DNS 配置中的国内 DNS 服务器地址走代理,以达到 DNS 分流目的
          "8.8.8.8",
          "1.1.1.1",
          "8.8.8.8/32",
          "91.108.4.0/22",
          "91.108.8.0/22",
          "91.108.12.0/22",
          "91.108.20.0/22",
          "91.108.36.0/23",
          "91.108.38.0/23",
          "91.108.56.0/22",
          "149.154.160.0/20",
          "149.154.164.0/22",
          "149.154.172.0/22",
          "74.125.0.0/16",
          "173.194.0.0/16",
          "172.217.0.0/16",
          "216.58.200.0/24",
          "216.58.220.0/24",
          "91.108.56.116",
          "91.108.56.0/24",
          "109.239.140.0/24",
          "149.154.167.0/24",
          "149.154.175.0/24"
        ],
        "outboundTag": "proxy" // 改为你自己代理的出站 tag
      },
      {
        "type": "field",
        "outboundTag": "proxy",
        "domain": [
          "ext:h2y.dat:gfw",
          "geosite:google",
          "geosite:github",
          "geosite:netflix",
          "geosite:steam",
          "geosite:telegram",
          "geosite:tumblr",
          "geosite:speedtest",
          "geosite:bbc",
          "domain:gvt1.com",
          "domain:textnow.com",
          "domain:twitch.tv",
          "domain:wikileaks.org",
          "domain:naver.com"
        ]
      },
      { // 广告拦截
        "type": "field",
        "domain": [
          "ext:h2y.dat:ad",
          "geosite:category-ads-all"
        ],
        "outboundTag": "block"
      },
      { // 直连中国大陆主流网站 ip 和 保留 ip
        "type": "field",
        "ip": [
          "geoip:private",
          "geoip:cn"
        ],
        "outboundTag": "direct"
      },
      { // 直连中国大陆主流网站域名
        "type": "field",
        "domain": [
          "domain:Mijia",
          "geosite:cn"
        ],
        "outboundTag": "direct"
      }
    ]
  }
}

6) 请附上出错时软件输出的错误日志。在 Linux 中,日志通常在 /var/log/v2ray/error.log 文件中。

客户端错误日志:

2020/07/01 21:35:56 [Warning] v2ray.com/core/app/router: resolve ip for Mijia Cloud > v2ray.com/core/app/dns: invalid domain name
2020/07/01 21:35:56 [Warning] v2ray.com/core/app/router: resolve ip for Mijia Cloud > v2ray.com/core/app/dns: invalid domain name
2020/07/01 21:36:05 [Warning] failed to handler mux client connection > v2ray.com/core/proxy/vmess/outbound: connection ends > v2ray.com/core/proxy/vmess/outbound: failed to read header > v2ray.com/core/proxy/vmess/encoding: failed to read response header > websocket: close 1000 (normal)
2020/07/01 21:36:22 [Warning] v2ray.com/core/app/router: resolve ip for Mijia Cloud > v2ray.com/core/app/dns: invalid domain name

7) 请附上访问日志。在 Linux 中,日志通常在 /var/log/v2ray/access.log 文件中。

   日志空白

此外,还有个问题,按上述教程在树莓派上设置透明代理后,CPU一会儿就跑满了(TOP里百分之300%多)

   top - 16:28:57 up  1:26,  3 users,  load average: 4.74, 6.96, 6.65
Tasks: 184 total,   2 running, 181 sleeping,   0 stopped,   1 zombie
%Cpu(s): 44.7 us, 32.7 sy,  0.0 ni,  5.2 id,  0.1 wa,  0.0 hi, 17.3 si,  0.0 st
MiB Mem :   3906.0 total,   1122.1 free,    904.3 used,   1879.6 buff/cache
MiB Swap:    100.0 total,    100.0 free,      0.0 used.   2756.0 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
 4226 root      20   0  820040 479916  12508 S 366.2  12.0 108:25.86 v2ray
Bug

All 6 comments

这也太奇葩了吧,Mijia Cloud 是什么域名,这恐怕应该去小米那边报问题。

好像是域名嗅探的问题 #1913 ,似乎有凑活的解决方案,但我没看懂。。

我也有类似情况, android手机安装了 tplink ipcam app, 4.25.0前好像没这问题(不确定)
不知为什麽会出现 *.tplinkcloud.com, 但查看dns纪录没有查询过 *.tplinkcloud.com
个人怀疑 dokodemo sniffing destoverride 出了问题(也是不确定)

    "sniffing": {
        "enabled": true,
        "destOverride": [
            "http","tls"
        ]
    },
2020/06/27 12:47:00 [Info] [4173284080] v2ray.com/core/app/dispatcher: sniffed domain: *.tplinkcloud.com
2020/06/27 12:47:00 [Info] [4173284080] v2ray.com/core/app/dispatcher: taking detour [out-direct] for [tcp:*.tplinkcloud.com:443]
2020/06/27 12:47:00 [Info] [4173284080] v2ray.com/core/proxy/freedom: opening connection to tcp:*.tplinkcloud.com:443
2020/06/27 12:47:00 [Info] [4173284080] v2ray.com/core/transport/internet/tcp: dialing TCP to tcp:*.tplinkcloud.com:443
2020/06/27 12:47:00 [Info] [4173284080] v2ray.com/core/transport/internet/tcp: dialing TCP to tcp:*.tplinkcloud.com:443
2020/06/27 12:47:00 [Info] [4173284080] v2ray.com/core/transport/internet/tcp: dialing TCP to tcp:*.tplinkcloud.com:443
2020/06/27 12:47:01 [Info] [4173284080] v2ray.com/core/transport/internet/tcp: dialing TCP to tcp:*.tplinkcloud.com:443
2020/06/27 12:47:01 [Info] [4173284080] v2ray.com/core/transport/internet/tcp: dialing TCP to tcp:*.tplinkcloud.com:443
2020/06/27 12:47:01 [Info] [4173284080] v2ray.com/core/app/proxyman/outbound: failed to process outbound traffic > v2ray.com/core/proxy/freedom: 
failed to open connection to tcp:*.tplinkcloud.com:443 > v2ray.com/core/common/retry: 
[dial tcp: lookup *.tplinkcloud.com: no such host] > v2ray.com/core/common/retry: all retry attempts failed

我在v2前router张以下ip range直连就正常
但没空继续测试, 只能宿小范围到以下6个doamin

app-server.iot.i.tplinknbu.com
aps1-relay-dcipc.i.tplinknbu.com
n-wap-gw.tplinkcloud.com
n-use1-wap-gw.tplinkcloud.com
sg-stun.tplinkcloud.com

Try this patch:

This is what I have tweaked on the source code to make v2ray ignore invalid domain name and use the original IP address.
By this tweak, my XiaoMi devices work again in my WiFi environment.

However, this is just a hack, the real bug is in the "domain sniffing" part.
I'm new to Go language, so I didn't spend time on reading the "domain sniffing" source code.

This bug still needs to be fixed by the author.

diff --git a/app/dispatcher/default.go b/app/dispatcher/default.go
index ef2ec44c..24b98b99 100644
--- a/app/dispatcher/default.go
+++ b/app/dispatcher/default.go
@@ -217,8 +217,13 @@ func (d *DefaultDispatcher) Dispatch(ctx context.Context, destination net.Destin
                        if err == nil && shouldOverride(result, sniffingRequest.OverrideDestinationForProtocol) {
                                domain := result.Domain()
                                newError("sniffed domain: ", domain).WriteToLog(session.ExportIDToError(ctx))
-                               destination.Address = net.ParseAddress(domain)
-                               ob.Target = destination
+                               newError("domain: ", domain, "'s original IP address is ", destination.Address).WriteToLog(session.ExportIDToError(ctx))
+                               if strings.Contains(domain, " ") {
+                                       newError("invalid domain address \"", domain, "\", ignored...").WriteToLog(session.ExportIDToError(ctx))
+                               } else {
+                                       destination.Address = net.ParseAddress(domain)
+                                       ob.Target = destination
+                               }
                        }
                        d.routedDispatch(ctx, outbound, destination)
                }()

After applying my patch, and re-compile your v2ray binary, the v2ray output on the router would be:

2020/07/12 16:30:38 [Info] [1193120751] v2ray.com/core/app/dispatcher: sniffed domain: Mijia Cloud
2020/07/12 16:30:38 [Info] [1193120751] v2ray.com/core/app/dispatcher: domain: Mijia Cloud's original IP address is 120.92.65.240
2020/07/12 16:30:38 [Info] [1193120751] v2ray.com/core/app/dispatcher: invalid domain address "Mijia Cloud", ignored...
2020/07/12 16:30:38 [Info] [1193120751] v2ray.com/core/app/dispatcher: taking detour [OutDirectTag] for [tcp:120.92.65.240:443]
2020/07/12 16:30:38 [Info] [1193120751] v2ray.com/core/proxy/freedom: opening connection to tcp:120.92.65.240:443

遇到同样的问题

可以在iptables里面设置将对应设备的流量不经过v2ray代理

Was this page helpful?
0 / 5 - 0 ratings