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

outbound为trojan,关闭mux,内置dns同时查询A和AAAA记录时,AAAA查询失败 #2440

Closed
celeron633 opened this issue Mar 28, 2023 · 11 comments

Comments

@celeron633
Copy link

celeron633 commented Mar 28, 2023

update: 2023-03-31
经过关闭trojan协议的tls层抓取报文发现,客户端发给服务器的请求(udp associate)包含A和AAAA,但是服务器只回了A记录:

客户端日志(增加了部分打印payload的)

2023/04/01 00:47:25 [Debug] transport/internet/udp: Dispatch... 0001010000010000000000000377777703636e6e03636f6d0000010001
2023/04/01 00:47:25 [Debug] transport/internet/udp: dispatch request to: udp:8.8.8.8:53
2023/04/01 00:47:25 [Info] transport/internet/udp: establishing new connection for udp:8.8.8.8:53
2023/04/01 00:47:25 [Debug] app/dns: call Dispatch end
2023/04/01 00:47:25 [Debug] app/dns: call Dispatch begin
2023/04/01 00:47:25 [Debug] transport/internet/udp: Dispatch... 0002010000010000000000000377777703636e6e03636f6d00001c0001
2023/04/01 00:47:25 [Debug] transport/internet/udp: dispatch request to: udp:8.8.8.8:53
2023/04/01 00:47:25 [Debug] transport/internet/udp: handleInput...

客户端发往服务器:(包含A和AAAA,部分包内容,去掉了部分SHA224信息)

0050   66 65 37 39 38 64 37 38 64 30 37 38 39 37 61 36   fe798d78d07897a6
0060   62 64 34 61 34 39 62 35 64 63 35 38 63 34 0d 0a   bd4a49b5dc58c4..
0070   03 01 08 08 08 08 00 35 0d 0a 01 08 08 08 08 00   .......5........
0080   35 00 3a 0d 0a 00 01 01 00 00 01 00 00 00 00 00   5.:.............
0090   00 03 77 77 77 03 63 6e 6e 03 63 6f 6d 00 00 01   ..www.cnn.com...
00a0   00 01 00 02 01 00 00 01 00 00 00 00 00 00 03 77   ...............w
00b0   77 77 03 63 6e 6e 03 63 6f 6d 00 00 1c 00 01      ww.cnn.com.....

服务器回包,只包含A记录:

0000   18 c0 4d dd 21 b5 60 be b4 01 b4 98 08 00 45 00   ..M.!.`.......E.
0010   00 60 74 0a 40 00 40 06 06 d7 c0 a8 1f 02 c0 a8   .`t.@.@.........
0020   1f 64 05 a3 2c 2f b6 11 43 54 fe 78 f2 8a 50 18   .d..,/..CT.x..P.
0030   01 f5 7b 0c 00 00 01 08 08 08 08 00 35 00 2d 0d   ..{.........5.-.
0040   0a 00 01 81 80 00 01 00 01 00 00 00 00 03 77 77   ..............ww
0050   77 03 63 6e 6e 03 63 6f 6d 00 00 01 00 01 c0 0c   w.cnn.com.......
0060   00 01 00 01 00 00 00 3c 00 04 92 4b 73 05         .......<...Ks.

update:2023-03-30
经过换多个outbound配置进行测试,发现outbound是trojan,以及关闭mux的情况下,若内置dns同时查询A和AAAA记录(例如route策略为IPOnDemend,freedom出口按IP,最简复现配置晚些提供。),开放一个inbound为socks5或者http,然后curl使用这个inbound,则会触发这个bug(需要远程服务器延迟比较大)。
@mydogshitgold 使用docker镜像和ymal配置也复现了这个bug,使用vmess和vless则不涉及。

你正在使用哪个版本的 V2Ray?

[Warning] V2Ray 5.4.1 started
服务器版本相同

你的使用场景是什么?

按照白话文配置的透明代理环境,透明代理模式下,一切工作正常,dns根据域名也能合理分流国内国外。
教程链接:https://guide.v2fly.org/app/tproxy.html
环境信息:
v2ray网关:192.168.31.2, N5105 x86,ubuntu 22.04,tproxy端口1088,socks5服务端口1080

IPTABLES配置如下:

    echo "start tproxy begin"

    # 设置策略路由
    ip rule add fwmark 1 table 100 
    ip route add local 0.0.0.0/0 dev lo table 100

    # 代理局域网设备
    iptables -t mangle -N V2RAY
    iptables -t mangle -A V2RAY -d 127.0.0.1/32 -j RETURN
    iptables -t mangle -A V2RAY -d 224.0.0.0/4 -j RETURN 
    iptables -t mangle -A V2RAY -d 255.255.255.255/32 -j RETURN 
    iptables -t mangle -A V2RAY -d 192.168.0.0/16 -p tcp -j RETURN # 直连局域网,避免 V2Ray 无法启动时无法连网关的 SSH,如果你配置的是其他网段(如 10.x.x.x 等),则修改成自己的
    iptables -t mangle -A V2RAY -d 192.168.0.0/16 -p udp ! --dport 53 -j RETURN # 直连局域网,53 端口除外(因为要使用 V2Ray 的 DNS)
    iptables -t mangle -A V2RAY -j RETURN -m mark --mark 0xff    # 直连 SO_MARK 为 0xff 的流量(0xff 是 16 进制数,数值上等同与上面V2Ray 配置的 255),此规则目的是解决v2ray占用大量CPU(https://github.com/v2ray/v2ray-core/issues/2621)
    iptables -t mangle -A V2RAY -p udp -j TPROXY --on-ip 127.0.0.1 --on-port 1088 --tproxy-mark 1 # 给 UDP 打标记 1,转发至 12345 端口
    iptables -t mangle -A V2RAY -p tcp -j TPROXY --on-ip 127.0.0.1 --on-port 1088 --tproxy-mark 1 # 给 TCP 打标记 1,转发至 12345 端口
    iptables -t mangle -A PREROUTING -j V2RAY # 应用规则

    # 代理网关本机
    iptables -t mangle -N V2RAY_MASK 
    iptables -t mangle -A V2RAY_MASK -d 224.0.0.0/4 -j RETURN 
    iptables -t mangle -A V2RAY_MASK -d 255.255.255.255/32 -j RETURN 
    iptables -t mangle -A V2RAY_MASK -d 192.168.0.0/16 -p tcp -j RETURN # 直连局域网
    iptables -t mangle -A V2RAY_MASK -d 192.168.0.0/16 -p udp ! --dport 53 -j RETURN # 直连局域网,53 端口除外(因为要使用 V2Ray 的 DNS)
    iptables -t mangle -A V2RAY_MASK -j RETURN -m mark --mark 0xff    # 直连 SO_MARK 为 0xff 的流量(0xff 是 16 进制数,数值上等同与上面V2Ray 配置的 255),此规则目的是避免代理本机(网关)流量出现回环问题
    iptables -t mangle -A V2RAY_MASK -p udp -j MARK --set-mark 1   # 给 UDP 打标记,重路由
    iptables -t mangle -A V2RAY_MASK -p tcp -j MARK --set-mark 1   # 给 TCP 打标记,重路由
    iptables -t mangle -A OUTPUT -j V2RAY_MASK # 应用规则

    # 新建 DIVERT 规则,避免已有连接的包二次通过 TPROXY,理论上有一定的性能提升
    iptables -t mangle -N DIVERT
    iptables -t mangle -A DIVERT -j MARK --set-mark 1
    iptables -t mangle -A DIVERT -j ACCEPT
    iptables -t mangle -I PREROUTING -p tcp -m socket -j DIVERT

    echo "start tproxy end"

你看到的异常现象是什么?

浏览器使用socks5代理访问(switchyomega)的情况下,打开网页非常慢,需要5-6秒才能打开(用海外dns解析的),国内网站正常(使用阿里dns解析的),日志出现大量dns解析超时的报错,奇怪的是remote已经返回结果了,然后update dns记录时报错,然后打印context deadline exceeded

你期待看到的正常表现是怎样的?

socks5使用正常

请附上你的配置

服务端配置:

需要同时支持trojan和ss-websocket for windows模式,服务端应该没有任何问题

{
    "log": {
        "loglevel": "info"
    },
    "inbounds": [
        {
            "port": "1",
            "protocol": "trojan",
            "settings": {
                "clients": [
                    {
                        "password":"password",
                        "email": "[email protected]"
                    }
                ],
                "fallbacks": [
                    {
                        "dest": 80
                    }
                ]
            },
            "streamSettings": {
                "network": "tcp",
                "security": "tls",
                "tlsSettings": {
                    "alpn": [
                        "http/1.1"
                    ],
                    "certificates": [
                        {
                            "certificateFile": "path_to_fullchain.cer",
                            "keyFile": "path_to_private_key.key"
                        }
                    ]
                }
            }
        },
        {
            "port": "2",
            "protocol": "trojan",
            "settings": {
                "clients": [
                    {
                        "password":"password",
                        "email": "[email protected]"
                    }
                ],
                "fallbacks": [
                    {
                        "dest": 80
                    }
                ]
            },
            "streamSettings": {
                "network": "tcp",
                "security": "tls",
                "tlsSettings": {
                    "alpn": [
                        "http/1.1"
                    ],
                    "certificates": [
                        {
                            "certificateFile": "path_to_fullchain.cer",
                            "keyFile": "path_to_private_key.key"
                        }
                    ]
                }
            }
        },
        {
            "port": 3,
            "listen": "127.0.0.1",
            "protocol": "shadowsocks",
            "settings": {
                "method": "chacha20-ietf-poly1305",
                "ota": false,
                "password": "password",
                "network": "tcp"
            },
            "sniffing": {
                "enabled": true,
                "destOverride": ["http", "tls"]
            }
        },
        {
            "port": "4",
            "listen": "0.0.0.0",
            "protocol": "dokodemo-door",
            "tag": "ws-dokodemo",
            "settings": {
                "address": "v1.mux.cool",
                "followRedirect": false,
                "network": "tcp"
            },
            "streamSettings": {
                "network": "ws",
                "wsSettings": {
                    "path": "/"
                }
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom",
            "tag": "direct"
        },
        {
            "protocol": "blackhole",
            "tag": "block"
        },
        {
            "protocol": "socks",
            "tag":"socks5-out",
            "settings": {
                "servers": [
                     {
                        "address": "127.0.0.1",
                        "port": 8090
                    }
                ]
            }
        },
        {
            "protocol": "freedom",
            "tag": "ss-mux",
            "settings": {
                "redirect": "127.0.0.1:9015"
            }
        }
    ],
    "routing": {
        "domainStrategy": "AsIs",
        "rules": [
            {
                "type": "field",
                "inboundTag": [
                    "ws-dokodemo"
                ],
                "outboundTag": "ss-mux"
            },
            {
                "type": "field",
                "ip": [
                    "geoip:private"
                ],
                "outboundTag": "block"
            },
            {
                "type": "field", 
                "domain": [
                    "geosite:category-ads-all"
                ],
                "outboundTag": "block"
            },
            {
                "type": "field",
                "domain": [
                    "geosite:netflix", 
                    "geosite:openai"
                ],
                "outboundTag": "socks5-out"
            }
        ]
    }
}

客户端配置:

// 在这里附上客户端配置
{
    "log": {
        "loglevel": "debug"
    },
    "inbounds": [
        {
            "tag":"transparent",
            "port": 1088,
            "protocol": "dokodemo-door",
            "settings": {
                "network": "tcp,udp",
                "followRedirect": true
            },
            "sniffing": {
                "enabled": true,
                "destOverride": [
                    "http",
                    "tls"
                ]
            },
            "streamSettings": {
                "sockopt": {
                    "tproxy": "tproxy",
                    "mark": 255
                }
            }
        },
        {
            "port": 1080, 
            "protocol": "socks",
            "sniffing": {
                "enabled": true,
                "destOverride": ["http", "tls"]
            },
            "settings": {
                "auth": "noauth"
            }
        }
    ],
    "outbounds": [
        {
            "tag": "proxy",
            "protocol": "trojan",
            "settings": {
                "servers": [
                    {
                        "address": "${myDomain2}",
                        "method": "chacha20",
                        "ota": false,
                        "password": "${myPass}",
                        "port": 443,
                        "level": 1,
                        "flow": ""
                    }
                ]
            },
            "streamSettings": {
                "network": "tcp",
                "security": "tls",
                "tlsSettings": {
                    "allowInsecure": true,
                    "serverName": "${myDomain2}",
                    "fingerprint": ""
                },
                "sockopt": {
                    "mark": 255
                }
            },
            "mux": {
                "enabled": false,
                "concurrency": -1
            }
        },
        {
            "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": {
        "hosts": {
            "${myDomain1}": "${myIP1}",
            "${myDomain2}": "${myIP2}"
        },
        "servers": [
            {
                "address": "223.5.5.5",
                "port": 53,
                "domains": [
                    "geosite:cn",
                    "ntp.org",
                    "${myDomain2}",
                    "${myDomain1}"
                ]
            },
            {
                "address": "114.114.114.114",
                "port": 53,
                "domains": [
                    "geosite:cn",
                    "ntp.org",
                    "${myDomain2}",
                    "${myDomain1}"
                ]
            },
            {
                "address": "8.8.8.8",
                "port": 53,
                "domains": [
                    "geosite:geolocation-!cn"
                ]
            },
            {
                "address": "1.1.1.1",
                "port": 53,
                "domains": [
                    "geosite:geolocation-!cn"
                ]
            }
        ]
    },
    "routing": {
        "domainStrategy": "IPOnDemand",
        "rules": [
            {
                "type": "field",
                "inboundTag": [
                    "transparent"
                ],
                "port": 53,
                "network": "udp",
                "outboundTag": "dns-out" 
            },        
            {
                "type": "field",
                "inboundTag": [
                    "transparent"
                ],
                "port": 123,
                "network": "udp",
                "outboundTag": "direct" 
            },        
            {
                "type": "field", 
                "ip": [ 
                    "223.5.5.5",
                    "114.114.114.114"
                ],
                "outboundTag": "direct"
            },
            {
                "type": "field",
                "ip": [ 
                    "8.8.8.8",
                    "1.1.1.1"
                ],
                "outboundTag": "proxy"
            },
            {
                "type": "field", 
                "domain": [
                    "geosite:category-ads-all"
                ],
                "outboundTag": "block"
            },
            {
                "type": "field",
                "protocol":["bittorrent"], 
                "outboundTag": "direct"
            },
            {
                "type": "field", 
                "ip": [
                    "geoip:private",
                    "geoip:cn"
                ],
                "outboundTag": "direct"
            },
            {
                "type": "field", 
                "domain": [
                    "geosite:cn"
                ],
                "outboundTag": "direct"
            }
        ]
    }
}

请附上出错时软件输出的错误日志

服务器端错误日志:
应该与服务器无关,服务器一切正常

// 在这里附上服务器端日志
Mar 28 09:46:18 linux v2ray[88347]: 2023/03/28 09:46:18 [Info] [3657082878] proxy/trojan: tunnelling request to udp:8.8.8.8:53
Mar 28 09:46:18 linux v2ray[88347]: 2023/03/28 09:46:18 [Debug] [3657082878] transport/internet/udp: dispatch request to: udp:8.8.8.8:53
Mar 28 09:46:18 linux v2ray[88347]: 2023/03/28 09:46:18 [Info] transport/internet/udp: establishing new connection for udp:8.8.8.8:53
Mar 28 09:46:18 linux v2ray[88347]: 2023/03/28 09:46:18 [Warning] [3657082878] app/dispatcher: default route for udp:8.8.8.8:53
Mar 28 09:46:18 linux v2ray[88347]: 2023/03/28 09:46:18 [Info] [3657082878] proxy/freedom: opening connection to udp:8.8.8.8:53
Mar 28 09:46:18 linux v2ray[88347]: 2023/03/28 09:46:18 tcp:${myCNIP}:14783 accepted udp:8.8.8.8:53 [direct] email: love@v2fly.org
Mar 28 09:46:20 linux v2ray[88347]: 2023/03/28 09:46:20 [Info] [1357748023] proxy/trojan: firstLen = 137
Mar 28 09:46:20 linux v2ray[88347]: 2023/03/28 09:46:20 [Info] [1357748023] proxy/trojan: tunnelling request to udp:1.1.1.1:53
Mar 28 09:46:20 linux v2ray[88347]: 2023/03/28 09:46:20 [Debug] [1357748023] transport/internet/udp: dispatch request to: udp:1.1.1.1:53
Mar 28 09:46:20 linux v2ray[88347]: 2023/03/28 09:46:20 [Info] transport/internet/udp: establishing new connection for udp:1.1.1.1:53
Mar 28 09:46:20 linux v2ray[88347]: 2023/03/28 09:46:20 [Warning] [1357748023] app/dispatcher: default route for udp:1.1.1.1:53
Mar 28 09:46:20 linux v2ray[88347]: 2023/03/28 09:46:20 [Info] [1357748023] proxy/freedom: opening connection to udp:1.1.1.1:53
Mar 28 09:46:20 linux v2ray[88347]: 2023/03/28 09:46:20 tcp:${myCNIP}:14810 accepted udp:1.1.1.1:53 [direct] email: love@v2fly.org
Mar 28 09:46:24 linux v2ray[88347]: 2023/03/28 09:46:24 [Info] [391554293] proxy/trojan: firstLen = 151
Mar 28 09:46:24 linux v2ray[88347]: 2023/03/28 09:46:24 [Info] [391554293] proxy/trojan: received request for tcp:www.cnn.com:80
Mar 28 09:46:24 linux v2ray[88347]: 2023/03/28 09:46:24 [Warning] [391554293] app/dispatcher: default route for tcp:www.cnn.com:80
Mar 28 09:46:24 linux v2ray[88347]: 2023/03/28 09:46:24 [Info] [391554293] proxy/freedom: opening connection to tcp:www.cnn.com:80
Mar 28 09:46:24 linux v2ray[88347]: 2023/03/28 09:46:24 [Info] [391554293] transport/internet/tcp: dialing TCP to tcp:www.cnn.com:80
Mar 28 09:46:24 linux v2ray[88347]: 2023/03/28 09:46:24 ${myCNIP}:14824 accepted tcp:www.cnn.com:80 [direct] email: love@v2fly.org

客户端错误日志:
客户端有报错

-- stuck here那里有阻塞一会,时间和服务器日志不同因为GMT不同,UTC是一样的

// 在这里附上客户端日志
Mar 28 13:46:15 ubuntu v2ray[20521]: 2023/03/28 13:46:15 192.168.31.2:55927 accepted udp:8.8.8.8:53 [dns-out]
Mar 28 13:46:15 ubuntu v2ray[20521]: 2023/03/28 13:46:15 [Info] [3705716181] app/dispatcher: taking detour [dns-out] for [udp:8.8.8.8:53]
Mar 28 13:46:15 ubuntu v2ray[20521]: 2023/03/28 13:46:15 192.168.31.2:40494 accepted udp:8.8.8.8:53 [dns-out]
Mar 28 13:46:15 ubuntu v2ray[20521]: 2023/03/28 13:46:15 [Info] [3705716181] proxy/dns: handling DNS traffic to udp:8.8.8.8:53
Mar 28 13:46:15 ubuntu v2ray[20521]: 2023/03/28 13:46:15 [Info] app/dns: returning 1 IP(s) for domain ${myRemoteDomain} -> [${myRemoteIP}]
Mar 28 13:46:17 ubuntu v2ray[20521]: 2023/03/28 13:46:17 [Info] proxy/trojan: tunneling request to udp:8.8.8.8:53 via ${myRemoteDomain}:443
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Info] app/dns: UDP:8.8.8.8:53 got answer: www.cnn.com. TypeA -> [151.101.3.5 151.101.67.5 151.101.131.5 151.101.195.5] 3.889383616s
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Debug] app/dns: UDP:8.8.8.8:53 updating IP records for domain:www.cnn.com.
-- stuck here
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Info] app/dns: failed to lookup ip for domain www.cnn.com at server UDP:8.8.8.8:53 > context deadline exceeded
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Debug] app/dns: UDP:1.1.1.1:53 querying DNS for: www.cnn.com.
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Debug] transport/internet/udp: dispatch request to: udp:1.1.1.1:53
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Info] transport/internet/udp: establishing new connection for udp:1.1.1.1:53
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Debug] transport/internet/udp: dispatch request to: udp:1.1.1.1:53
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Info] app/dispatcher: taking detour [proxy] for [udp:1.1.1.1:53]
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Info] transport/internet/tcp: dialing TCP to tcp:${myRemoteDomain}:443
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Debug] transport/internet/udp: UDP original destination: udp:8.8.8.8:53
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Debug] transport/internet/udp: UDP original destination: udp:8.8.8.8:53
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Debug] [821394586] proxy/dokodemo: processing connection from: 192.168.31.2:38104
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Info] [821394586] proxy/dokodemo: received request for 192.168.31.2:38104
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Debug] [3250449119] proxy/dokodemo: processing connection from: 192.168.31.2:40349
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Info] [3250449119] proxy/dokodemo: received request for 192.168.31.2:40349
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Info] [3250449119] app/dispatcher: taking detour [dns-out] for [udp:8.8.8.8:53]
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Info] [821394586] app/dispatcher: taking detour [dns-out] for [udp:8.8.8.8:53]
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Info] [3250449119] proxy/dns: handling DNS traffic to udp:8.8.8.8:53
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Info] [821394586] proxy/dns: handling DNS traffic to udp:8.8.8.8:53
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 192.168.31.2:40349 accepted udp:8.8.8.8:53 [dns-out]
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 192.168.31.2:38104 accepted udp:8.8.8.8:53 [dns-out]
Mar 28 13:46:19 ubuntu v2ray[20521]: 2023/03/28 13:46:19 [Info] app/dns: returning 1 IP(s) for domain ${myRemoteDomain} -> [${myRemoteIP}]
Mar 28 13:46:20 ubuntu v2ray[20521]: 2023/03/28 13:46:20 [Info] proxy/trojan: tunneling request to udp:1.1.1.1:53 via ${myRemoteDomain}:443
Mar 28 13:46:20 ubuntu v2ray[20521]: 2023/03/28 13:46:20 [Info] app/dns: UDP:1.1.1.1:53 got answer: www.cnn.com. TypeA -> [151.101.3.5 151.101.131.5 151.101.67.5 151.101.195.5] 627.827622ms
Mar 28 13:46:20 ubuntu v2ray[20521]: 2023/03/28 13:46:20 [Debug] app/dns: UDP:1.1.1.1:53 updating IP records for domain:www.cnn.com.
-- stuck here
Mar 28 13:46:23 ubuntu v2ray[20521]: 2023/03/28 13:46:23 [Info] app/dns: failed to lookup ip for domain www.cnn.com at server UDP:1.1.1.1:53 > context deadline exceeded
Mar 28 13:46:23 ubuntu v2ray[20521]: 2023/03/28 13:46:23 [Debug] app/dns: UDP:223.5.5.5:53 querying DNS for: www.cnn.com.
Mar 28 13:46:23 ubuntu v2ray[20521]: 2023/03/28 13:46:23 [Debug] transport/internet/udp: dispatch request to: udp:223.5.5.5:53
Mar 28 13:46:23 ubuntu v2ray[20521]: 2023/03/28 13:46:23 [Info] transport/internet/udp: establishing new connection for udp:223.5.5.5:53
Mar 28 13:46:23 ubuntu v2ray[20521]: 2023/03/28 13:46:23 [Debug] transport/internet/udp: dispatch request to: udp:223.5.5.5:53
Mar 28 13:46:23 ubuntu v2ray[20521]: 2023/03/28 13:46:23 [Info] app/dispatcher: taking detour [direct] for [udp:223.5.5.5:53]
Mar 28 13:46:23 ubuntu v2ray[20521]: 2023/03/28 13:46:23 [Info] proxy/freedom: opening connection to udp:223.5.5.5:53
Mar 28 13:46:23 ubuntu v2ray[20521]: 2023/03/28 13:46:23 [Info] app/dns: UDP:223.5.5.5:53 got answer: www.cnn.com. TypeA -> [151.101.111.5] 1.890059ms

第二个stuck here的地方,remote返回dns结果只有600多毫秒,但是也更新记录那里卡住然后失败了。
failed to lookup ip for domain www.cnn.com at server UDP:1.1.1.1:53 > context deadline exceeded

请附上访问日志

未配置,应该不涉及

// 在这里附上服务器端日志

其它相关的配置文件(如 Nginx)和相关日志

不涉及

如果 V2Ray 无法启动,请附上 --test 命令的输出

不涉及

如果 V2Ray 服务运行异常,请附上 journal 日志

不涉及

@celeron633
Copy link
Author

celeron633 commented Mar 28, 2023

若53端口增加一个任意门,打上tag,然后route这个tag到dns-in,解析也正常,配置如下:

{
    "log": {
        "loglevel": "debug"
    },
    "inbounds": [
        {
            "tag":"transparent",
            "port": 1088,
            "protocol": "dokodemo-door",
            "settings": {
                "network": "tcp,udp",
                "followRedirect": true
            },
            "sniffing": {
                "enabled": true,
                "destOverride": [
                    "http",
                    "tls"
                ]
            },
            "streamSettings": {
                "sockopt": {
                    "tproxy": "tproxy",
                    "mark": 255
                }
            }
        },
        {
            "port": 1080, 
            "protocol": "socks",
            "sniffing": {
                "enabled": true,
                "destOverride": ["http", "tls"]
            },
            "settings": {
                "auth": "noauth"
            }
        },
        {
            "tag":"dns-in",
            "port": 53,
            "protocol": "dokodemo-door",
            "settings": {
                "network": "udp"
            },
            "streamSettings": {
                "sockopt": {
                    "tproxy": "tproxy",
                    "mark": 255
                }
            }
        }
    ],
    "outbounds": [
        {
            "tag": "proxy",
            "protocol": "trojan",
            "settings": {
                "servers": [
                    {
                        "address": "${myDomain2}",
                        "method": "chacha20",
                        "ota": false,
                        "password": "${myPass}",
                        "port": 443,
                        "level": 1,
                        "flow": ""
                    }
                ]
            },
            "streamSettings": {
                "network": "tcp",
                "security": "tls",
                "tlsSettings": {
                    "allowInsecure": true,
                    "serverName": "${myDomain2}",
                    "fingerprint": ""
                },
                "sockopt": {
                    "mark": 255
                }
            },
            "mux": {
                "enabled": false,
                "concurrency": -1
            }
        },
        {
            "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": {
        "hosts": {
            "${myDomain1}": "${myIP1}",
            "${myDomain2}": "${myIP2}"
        },
        "servers": [
            {
                "address": "223.5.5.5",
                "port": 53,
                "domains": [
                    "geosite:cn",
                    "ntp.org",
                    "${myDomain2}",
                    "${myDomain1}"
                ]
            },
            {
                "address": "114.114.114.114",
                "port": 53,
                "domains": [
                    "geosite:cn",
                    "ntp.org",
                    "${myDomain2}",
                    "${myDomain1}"
                ]
            },
            {
                "address": "8.8.8.8",
                "port": 53,
                "domains": [
                    "geosite:geolocation-!cn"
                ]
            },
            {
                "address": "1.1.1.1",
                "port": 53,
                "domains": [
                    "geosite:geolocation-!cn"
                ]
            }
        ]
    },
    "routing": {
        "domainStrategy": "IPOnDemand",
        "rules": [
            {
                "type": "field",
                "inboundTag": [
                    "transparent",
                    "dns-in"
                ],
                "port": 53,
                "network": "udp",
                "outboundTag": "dns-out" 
            },        
            {
                "type": "field",
                "inboundTag": [
                    "transparent"
                ],
                "port": 123,
                "network": "udp",
                "outboundTag": "direct" 
            },        
            {
                "type": "field", 
                "ip": [ 
                    "223.5.5.5",
                    "114.114.114.114"
                ],
                "outboundTag": "direct"
            },
            {
                "type": "field",
                "ip": [ 
                    "8.8.8.8",
                    "1.1.1.1"
                ],
                "outboundTag": "proxy"
            },
            {
                "type": "field", 
                "domain": [
                    "geosite:category-ads-all"
                ],
                "outboundTag": "block"
            },
            {
                "type": "field",
                "protocol":["bittorrent"], 
                "outboundTag": "direct"
            },
            {
                "type": "field", 
                "ip": [
                    "geoip:private",
                    "geoip:cn"
                ],
                "outboundTag": "direct"
            },
            {
                "type": "field", 
                "domain": [
                    "geosite:cn"
                ],
                "outboundTag": "direct"
            }
        ]
    }
}

日志:

Mar 28 14:03:15 ubuntu v2ray[21132]: 2023/03/28 14:03:15 [Warning] V2Ray 5.4.1 started
Mar 28 14:03:31 ubuntu v2ray[21132]: 2023/03/28 14:03:31 [Debug] transport/internet/udp: UDP original destination: udp:192.168.31.2:53
Mar 28 14:03:31 ubuntu v2ray[21132]: 2023/03/28 14:03:31 [Debug] [2106271116] proxy/dokodemo: processing connection from: 192.168.31.100:58274
Mar 28 14:03:31 ubuntu v2ray[21132]: 2023/03/28 14:03:31 [Info] [2106271116] proxy/dokodemo: received request for 192.168.31.100:58274
Mar 28 14:03:31 ubuntu v2ray[21132]: 2023/03/28 14:03:31 [Info] [2106271116] app/dispatcher: taking detour [dns-out] for [udp:192.168.31.2:53]
Mar 28 14:03:31 ubuntu v2ray[21132]: 2023/03/28 14:03:31 [Info] [2106271116] proxy/dns: handling DNS traffic to udp:192.168.31.2:53
Mar 28 14:03:31 ubuntu v2ray[21132]: 2023/03/28 14:03:31 192.168.31.100:58274 accepted udp:192.168.31.2:53 [dns-out]
Mar 28 14:03:31 ubuntu v2ray[21132]: 2023/03/28 14:03:31 [Debug] [2068725410] proxy/dokodemo: processing connection from: 192.168.31.2:36193
Mar 28 14:03:31 ubuntu v2ray[21132]: 2023/03/28 14:03:31 [Info] [2068725410] app/proxyman/inbound: connection ends > proxy/dokodemo: unable to get destination
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Debug] transport/internet/udp: UDP original destination: udp:192.168.31.2:53
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Debug] [1346756803] proxy/dokodemo: processing connection from: 192.168.31.100:58275
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Info] [1346756803] proxy/dokodemo: received request for 192.168.31.100:58275
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Info] [1346756803] app/dispatcher: taking detour [dns-out] for [udp:192.168.31.2:53]
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Info] [1346756803] proxy/dns: handling DNS traffic to udp:192.168.31.2:53
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 192.168.31.100:58275 accepted udp:192.168.31.2:53 [dns-out]
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Debug] app/dns: domain cnn.com matches following rules: [geosite:geolocation-!cn(DNS idx:2) geosite:geolocation-!cn(DNS idx:3)]
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Debug] app/dns: domain cnn.com will use DNS in order: [UDP:8.8.8.8:53 UDP:1.1.1.1:53 UDP:223.5.5.5:53 UDP:114.114.114.114:53] [TypeA]
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Debug] app/dns: UDP:8.8.8.8:53 querying DNS for: cnn.com.
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Debug] transport/internet/udp: dispatch request to: udp:8.8.8.8:53
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Info] transport/internet/udp: establishing new connection for udp:8.8.8.8:53
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Info] app/dispatcher: taking detour [proxy] for [udp:8.8.8.8:53]
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Info] transport/internet/tcp: dialing TCP to tcp:${myDomain2}:443
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Debug] transport/internet/udp: UDP original destination: udp:8.8.8.8:53
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Debug] [3770314708] proxy/dokodemo: processing connection from: 192.168.31.2:51219
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Info] [3770314708] proxy/dokodemo: received request for 192.168.31.2:51219
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Debug] transport/internet/udp: UDP original destination: udp:8.8.8.8:53
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Debug] [959035624] proxy/dokodemo: processing connection from: 192.168.31.2:56057
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Info] [959035624] proxy/dokodemo: received request for 192.168.31.2:56057
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Info] [959035624] app/dispatcher: taking detour [dns-out] for [udp:8.8.8.8:53]
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Info] [959035624] proxy/dns: handling DNS traffic to udp:8.8.8.8:53
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 192.168.31.2:56057 accepted udp:8.8.8.8:53 [dns-out]
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 192.168.31.2:51219 accepted udp:8.8.8.8:53 [dns-out]
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Info] [3770314708] app/dispatcher: taking detour [dns-out] for [udp:8.8.8.8:53]
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Info] [3770314708] proxy/dns: handling DNS traffic to udp:8.8.8.8:53
Mar 28 14:03:33 ubuntu v2ray[21132]: 2023/03/28 14:03:33 [Info] app/dns: returning 1 IP(s) for domain ${myDomain2} -> [${myIP2}]
Mar 28 14:03:34 ubuntu v2ray[21132]: 2023/03/28 14:03:34 [Info] proxy/trojan: tunneling request to udp:8.8.8.8:53 via ${myDomain2}:443
Mar 28 14:03:35 ubuntu v2ray[21132]: 2023/03/28 14:03:35 [Info] app/dns: UDP:8.8.8.8:53 got answer: cnn.com. TypeA -> [151.101.131.5 151.101.67.5 151.101.3.5 151.101.195.5] 1.771113903s
-- mark here
Mar 28 14:03:35 ubuntu v2ray[21132]: 2023/03/28 14:03:35 [Debug] app/dns: UDP:8.8.8.8:53 updating IP records for domain:cnn.com.
Mar 28 14:03:35 ubuntu v2ray[21132]: 2023/03/28 14:03:35 [Debug] transport/internet/udp: UDP original destination: udp:192.168.31.2:53
Mar 28 14:03:35 ubuntu v2ray[21132]: 2023/03/28 14:03:35 [Debug] [551379548] proxy/dokodemo: processing connection from: 192.168.31.100:58276
Mar 28 14:03:35 ubuntu v2ray[21132]: 2023/03/28 14:03:35 [Info] [551379548] proxy/dokodemo: received request for 192.168.31.100:58276
Mar 28 14:03:35 ubuntu v2ray[21132]: 2023/03/28 14:03:35 [Info] [551379548] app/dispatcher: taking detour [dns-out] for [udp:192.168.31.2:53]
Mar 28 14:03:35 ubuntu v2ray[21132]: 2023/03/28 14:03:35 [Info] [551379548] proxy/dns: handling DNS traffic to udp:192.168.31.2:53
Mar 28 14:03:35 ubuntu v2ray[21132]: 2023/03/28 14:03:35 192.168.31.100:58276 accepted udp:192.168.31.2:53 [dns-out]
Mar 28 14:03:35 ubuntu v2ray[21132]: 2023/03/28 14:03:35 [Debug] app/dns: domain cnn.com matches following rules: [geosite:geolocation-!cn(DNS idx:2) geosite:geolocation-!cn(DNS idx:3)]
Mar 28 14:03:35 ubuntu v2ray[21132]: 2023/03/28 14:03:35 [Debug] app/dns: domain cnn.com will use DNS in order: [UDP:8.8.8.8:53 UDP:1.1.1.1:53 UDP:223.5.5.5:53 UDP:114.114.114.114:53] [TypeAAAA]
Mar 28 14:03:35 ubuntu v2ray[21132]: 2023/03/28 14:03:35 [Debug] app/dns: UDP:8.8.8.8:53 querying DNS for: cnn.com.
Mar 28 14:03:35 ubuntu v2ray[21132]: 2023/03/28 14:03:35 [Debug] transport/internet/udp: dispatch request to: udp:8.8.8.8:53
Mar 28 14:03:35 ubuntu v2ray[21132]: 2023/03/28 14:03:35 [Info] app/dns: UDP:8.8.8.8:53 got answer: cnn.com. TypeAAAA -> [[2a04:4e42:400::773] [2a04:4e42:a00::773] [2a04:4e42:c00::773] [2a04:4e42::773] [2a04:4e42:e00::773] [2a04:4e42:600::773] [2a04:4e42:200::773] [2a04:4e42:800::773]] 168.285036ms
Mar 28 14:03:35 ubuntu v2ray[21132]: 2023/03/28 14:03:35 [Debug] app/dns: UDP:8.8.8.8:53 updating IP records for domain:cnn.com.

虽然时间有点久,但是没有报错。

@mydogshitgold
Copy link
Contributor

Might you provide a collection of minimal configurations for the client, server, and iptables rules that would still be capable of replicating this issue?

@celeron633
Copy link
Author

Might you provide a collection of minimal configurations for the client, server, and iptables rules that would still be capable of replicating this issue?

Ok, I will provide later.
I can confirm this is a client side issue, my friend tested my client config without any iptables and replicated this(with his server in outbounds).

@celeron633
Copy link
Author

below is the minimal config i can provide to replicate the bug:
i replicated with iptables disabled, or it's just irrelevant with transparent proxy

{
    "log": {
        "loglevel": "debug"
    },
    "inbounds": [
        {
            "tag":"transparent",
            "port": 1088,
            "protocol": "dokodemo-door",
            "settings": {
                "network": "tcp,udp",
                "followRedirect": true
            },
            "sniffing": {
                "enabled": true,
                "destOverride": [
                    "http",
                    "tls"
                ]
            }
        },
        {
            "port": 1080, 
            "protocol": "socks",
            "sniffing": {
                "enabled": true,
                "destOverride": ["http", "tls"]
            },
            "settings": {
                "auth": "noauth"
            }
        }
    ],
    "outbounds": [
        {
            "tag": "proxy",
            "protocol": "trojan",
            "settings": {
                "servers": [
                    {
                        "address": "${proxyDomain}",
                        "method": "chacha20",
                        "ota": false,
                        "password": "${proxyPass}",
                        "port": 443,
                        "level": 1,
                        "flow": ""
                    }
                ]
            },
            "streamSettings": {
                "network": "tcp",
                "security": "tls",
                "tlsSettings": {
                    "allowInsecure": true,
                    "serverName": "${proxyDomain}",
                    "fingerprint": ""
                },
                "sockopt": {
                    "mark": 255
                }
            },
            "mux": {
                "enabled": false,
                "concurrency": -1
            }
        },
        {
            "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.5.5.5",
                "port": 53,
                "domains": [
                    "geosite:cn",
                    "ntp.org",
                    "${proxyDomain}"
                ]
            },
            {
                "address": "8.8.8.8",
                "port": 53,
                "domains": [
                    "geosite:geolocation-!cn"
                ]
            }
        ]
    },
    "routing": {
        "domainStrategy": "IPOnDemand",
        "rules": [
            {
                "type": "field",
                "inboundTag": [
                    "transparent"
                ],
                "port": 53,
                "network": "udp",
                "outboundTag": "dns-out" 
            },
            {
                "type": "field", 
                "ip": [ 
                    "223.5.5.5"
                ],
                "outboundTag": "direct"
            },
            {
                "type": "field",
                "ip": [ 
                    "8.8.8.8"
                ],
                "outboundTag": "proxy"
            },
            {
                "type": "field", 
                "ip": [
                    "geoip:private",
                    "geoip:cn"
                ],
                "outboundTag": "direct"
            },
            {
                "type": "field", 
                "domain": [
                    "geosite:cn"
                ],
                "outboundTag": "direct"
            }
        ]
    }
}

in wsl2, i run command:

curl -x socks5://192.168.31.2:1080 www.cnn.com -v

here is where this bug occured

Mar 29 13:39:18 ubuntu v2ray[17271]: 2023/03/29 13:39:18 [Debug] app/dns: domain www.cnn.com matches following rules: [geosite:geolocation-!cn(DNS idx:1)]
Mar 29 13:39:18 ubuntu v2ray[17271]: 2023/03/29 13:39:18 [Debug] app/dns: domain www.cnn.com will use DNS in order: [UDP:8.8.8.8:53 UDP:223.5.5.5:53] [TypeA TypeAAAA]
-- query A && AAAA together
Mar 29 13:39:18 ubuntu v2ray[17271]: 2023/03/29 13:39:18 [Debug] app/dns: client.QueryIP begin
Mar 29 13:39:18 ubuntu v2ray[17271]: 2023/03/29 13:39:18 [Debug] app/dns: udp QueryIP begin
Mar 29 13:39:18 ubuntu v2ray[17271]: 2023/03/29 13:39:18 [Debug] app/dns: sendQuery begin: www.cnn.com.
Mar 29 13:39:18 ubuntu v2ray[17271]: 2023/03/29 13:39:18 [Debug] app/dns: UDP:8.8.8.8:53 querying DNS for: www.cnn.com.
Mar 29 13:39:18 ubuntu v2ray[17271]: 2023/03/29 13:39:18 [Debug] transport/internet/udp: dispatch request to: udp:8.8.8.8:53
Mar 29 13:39:18 ubuntu v2ray[17271]: 2023/03/29 13:39:18 [Info] transport/internet/udp: establishing new connection for udp:8.8.8.8:53
Mar 29 13:39:18 ubuntu v2ray[17271]: 2023/03/29 13:39:18 [Debug] transport/internet/udp: dispatch request to: udp:8.8.8.8:53
Mar 29 13:39:18 ubuntu v2ray[17271]: 2023/03/29 13:39:18 [Info] app/dispatcher: taking detour [proxy] for [udp:8.8.8.8:53]
Mar 29 13:39:18 ubuntu v2ray[17271]: 2023/03/29 13:39:18 [Info] transport/internet/tcp: dialing TCP to tcp:${proxyDomain}:443
Mar 29 13:39:18 ubuntu v2ray[17271]: 2023/03/29 13:39:18 [Debug] app/dns: sendQuery end: www.cnn.com.
Mar 29 13:39:18 ubuntu v2ray[17271]: 2023/03/29 13:39:18 [Debug] app/dns: QueryIP select begin
Mar 29 13:39:19 ubuntu v2ray[17271]: 2023/03/29 13:39:19 [Info] proxy/trojan: tunneling request to udp:8.8.8.8:53 via ${proxyDomain}:443
Mar 29 13:39:19 ubuntu v2ray[17271]: 2023/03/29 13:39:19 [Info] app/dns: UDP:8.8.8.8:53 got answer: www.cnn.com. TypeA -> [151.101.3.5 151.101.67.5 151.101.131.5 151.101.195.5] 832.263115ms
Mar 29 13:39:19 ubuntu v2ray[17271]: 2023/03/29 13:39:19 [Debug] app/dns: A
Mar 29 13:39:19 ubuntu v2ray[17271]: 2023/03/29 13:39:19 [Debug] app/dns: UDP:8.8.8.8:53 updating IP records for domain:www.cnn.com.
Mar 29 13:39:19 ubuntu v2ray[17271]: 2023/03/29 13:39:19 [Debug] app/dns: 1
Mar 29 13:39:19 ubuntu v2ray[17271]: 2023/03/29 13:39:19 [Debug] app/dns: 2
Mar 29 13:39:19 ubuntu v2ray[17271]: 2023/03/29 13:39:19 [Debug] app/dns: 3
Mar 29 13:39:19 ubuntu v2ray[17271]: 2023/03/29 13:39:19 [Debug] app/dns: 4
Mar 29 13:39:19 ubuntu v2ray[17271]: 2023/03/29 13:39:19 [Debug] app/dns: 5
Mar 29 13:39:19 ubuntu v2ray[17271]: 2023/03/29 13:39:19 [Debug] app/dns: 6
Mar 29 13:39:19 ubuntu v2ray[17271]: 2023/03/29 13:39:19 [Debug] app/dns: B
-- mark here
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: QueryIP select end with errcontext deadline exceeded
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: client.QueryIP end
-- mark here
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Info] app/dns: failed to lookup ip for domain www.cnn.com at server UDP:8.8.8.8:53 > context deadline exceeded
-- mark here
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: client.QueryIP begin
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: udp QueryIP begin
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: sendQuery begin: www.cnn.com.
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: UDP:223.5.5.5:53 querying DNS for: www.cnn.com.
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] transport/internet/udp: dispatch request to: udp:223.5.5.5:53
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Info] transport/internet/udp: establishing new connection for udp:223.5.5.5:53
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] transport/internet/udp: dispatch request to: udp:223.5.5.5:53
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: sendQuery end: www.cnn.com.
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: QueryIP select begin
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Info] app/dispatcher: taking detour [direct] for [udp:223.5.5.5:53]
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Info] proxy/freedom: opening connection to udp:223.5.5.5:53
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Info] app/dns: UDP:223.5.5.5:53 got answer: www.cnn.com. TypeA -> [151.101.111.5] 1.731517ms
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: A
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: UDP:223.5.5.5:53 updating IP records for domain:www.cnn.com.
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: 1
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: 2
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: 3
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: 4
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: 5
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: 6
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: B
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Info] app/dns: UDP:223.5.5.5:53 got answer: www.cnn.com. TypeAAAA -> [[2a04:4e42:8c::773]] 5.005411ms
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: A
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: UDP:223.5.5.5:53 updating IP records for domain:www.cnn.com.
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: 1
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: 2
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: 3
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: 4
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: 5
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: 6
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: B
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: QueryIP select end
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Debug] app/dns: client.QueryIP end
Mar 29 13:39:22 ubuntu v2ray[17271]: 2023/03/29 13:39:22 [Warning] [589579102] app/dispatcher: default route for tcp:www.cnn.com:80

it seems a socks5 query will trigger A && AAAA dns query at the same time, and the A query will success and the AAAA will fail.
and the transparent dns query will query A and AAAA in two separate times and in such case it will success.

@celeron633
Copy link
Author

celeron633 commented Mar 29, 2023

update:

after replace

"mux": {
                "enabled": false,
                "concurrency": -1
            }

to

"mux": {
                "enabled": true
            }

this bug disappeared, and if you disable mux, it will occur.

with mux enabled, the dns app can get A && AAAA address at the same time.
i just copied this piece outbound config from v2rayN, and took no attention to this.😂
so, my conclusion:
if you use trojan(maybe other protocols as well) as outbound, and disable mux, use builtin dns server to route, and you will fail to reslove AAAA. (with a high latency remote server)

@mydogshitgold
Copy link
Contributor

mydogshitgold commented Mar 29, 2023

While a split configuration with two separate instances is still viable, for the sake of simplicity, I can reproduce the mentioned issues utilizing a minimal configuration that consolidates client and server setup on a fresh ubuntu:20.04 docker image with single instances of v2ray-core 5.4.1:

# yaml-language-server: $schema=https://cdn.jsdelivr.net/gh/EHfive/v2ray-jsonschema/v4-config.schema.json
log:
  loglevel: debug
inbounds:
  - tag: client_in
    protocol: socks
    port: 4000
    listen: 127.0.0.1
  - tag: server_in
    listen: 127.0.0.2
    port: 5000
    protocol: trojan
    settings:
      clients:
        - password: testing
outbounds:
  - tag: client_out
    protocol: trojan
    settings:
      servers:
        - address: 127.0.0.2
          port: 5000
          password: testing
  - tag: server_out
    protocol: freedom
dns:
  servers:
    - 1.1.1.1
routing:
  domainStrategy: IPOnDemand
  rules:
    - outboundTag: client_out
      ip:
        127.1.1.1
      type: field
    - outboundTag: client_out
      inboundTag: 
        - client_in
      type: field
    - outboundTag: server_out
      inboundTag: 
        - server_in
      type: field

The utilization of v2ray trojan as outbound sans mux invokes the built-in DNS to initiate both A and AAAA queries. However, after thorough validation through tcpdump, it was discovered that solely an A request is dispatched to the configured DNS server, resulting in the failure of the AAAA query.

When employing vmess or vless, this issue does not arise.


@HxGned

Could you please rephrase the initial title and post body, given that this issues is inconsequential to the subject of transparent proxy or client inbound?

@celeron633
Copy link
Author

While a split configuration with two separate instances is still viable, for the sake of simplicity, I can reproduce the mentioned issues utilizing a minimal configuration that consolidates client and server setup on a fresh ubuntu:20.04 docker image with single instances of v2ray-core 5.4.1:

# yaml-language-server: $schema=https://cdn.jsdelivr.net/gh/EHfive/v2ray-jsonschema/v4-config.schema.json
log:
  loglevel: debug
inbounds:
  - tag: client_in
    protocol: socks
    port: 4000
    listen: 127.0.0.1
  - tag: server_in
    listen: 127.0.0.2
    port: 5000
    protocol: trojan
    settings:
      clients:
        - password: testing
outbounds:
  - tag: client_out
    protocol: trojan
    settings:
      servers:
        - address: 127.0.0.2
          port: 5000
          password: testing
  - tag: server_out
    protocol: freedom
dns:
  servers:
    - 1.1.1.1
routing:
  domainStrategy: IPOnDemand
  rules:
    - outboundTag: client_out
      ip:
        127.1.1.1
      type: field
    - outboundTag: client_out
      inboundTag: 
        - client_in
      type: field
    - outboundTag: server_out
      inboundTag: 
        - server_in
      type: field

The utilization of v2ray trojan as outbound sans mux invokes the built-in DNS to initiate both A and AAAA queries. However, after thorough validation through tcpdump, it was discovered that solely an A request is dispatched to the configured DNS server, resulting in the failure of the AAAA query.

When employing vmess or vless, this issue does not arise.

@HxGned

Could you please rephrase the initial title and post body, given that this issues is inconsequential to the subject of transparent proxy or client inbound?

ok will update soon

@celeron633 celeron633 changed the title v2ray客户端在透明代理+socks5的配置模式下,socks5的dns解析异常 outbound为trojan,关闭mux,内置dns同时查询A和AAAA记录时,AAAA查询失败 Mar 30, 2023
@dyhkwong
Copy link
Contributor

Is this a duplicate of #1795?

@celeron633
Copy link
Author

Is this a duplicate of #1795?

seems yes, i am trying to work this out via debuging.

@dyhkwong
Copy link
Contributor

try

git diff v5.4.1
diff --git a/proxy/trojan/protocol.go b/proxy/trojan/protocol.go
index 21e6a5a8..dba2cf76 100644
--- a/proxy/trojan/protocol.go
+++ b/proxy/trojan/protocol.go
@@ -101,11 +101,8 @@ type PacketWriter struct {

 // WriteMultiBuffer implements buf.Writer
 func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
-       b := make([]byte, maxLength)
-       for !mb.IsEmpty() {
-               var length int
-               mb, length = buf.SplitBytes(mb, b)
-               if _, err := w.writePacket(b[:length], w.Target); err != nil {
+       for _, b := range mb {
+               if _, err := w.writePacket(b.Bytes(), w.Target); err != nil {
                        buf.ReleaseMulti(mb)
                        return err
                }
@@ -116,11 +113,8 @@ func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {

 // WriteMultiBufferWithMetadata writes udp packet with destination specified
 func (w *PacketWriter) WriteMultiBufferWithMetadata(mb buf.MultiBuffer, dest net.Destination) error {
-       b := make([]byte, maxLength)
-       for !mb.IsEmpty() {
-               var length int
-               mb, length = buf.SplitBytes(mb, b)
-               if _, err := w.writePacket(b[:length], dest); err != nil {
+       for _, b := range mb {
+               if _, err := w.writePacket(b.Bytes(), dest); err != nil {
                        buf.ReleaseMulti(mb)
                        return err
                }

@celeron633
Copy link
Author

try

git diff v5.4.1
diff --git a/proxy/trojan/protocol.go b/proxy/trojan/protocol.go
index 21e6a5a8..dba2cf76 100644
--- a/proxy/trojan/protocol.go
+++ b/proxy/trojan/protocol.go
@@ -101,11 +101,8 @@ type PacketWriter struct {

 // WriteMultiBuffer implements buf.Writer
 func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
-       b := make([]byte, maxLength)
-       for !mb.IsEmpty() {
-               var length int
-               mb, length = buf.SplitBytes(mb, b)
-               if _, err := w.writePacket(b[:length], w.Target); err != nil {
+       for _, b := range mb {
+               if _, err := w.writePacket(b.Bytes(), w.Target); err != nil {
                        buf.ReleaseMulti(mb)
                        return err
                }
@@ -116,11 +113,8 @@ func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {

 // WriteMultiBufferWithMetadata writes udp packet with destination specified
 func (w *PacketWriter) WriteMultiBufferWithMetadata(mb buf.MultiBuffer, dest net.Destination) error {
-       b := make([]byte, maxLength)
-       for !mb.IsEmpty() {
-               var length int
-               mb, length = buf.SplitBytes(mb, b)
-               if _, err := w.writePacket(b[:length], dest); err != nil {
+       for _, b := range mb {
+               if _, err := w.writePacket(b.Bytes(), dest); err != nil {
                        buf.ReleaseMulti(mb)
                        return err
                }

genius👍, it worked

client side log:

2023/04/01 09:06:19 [Info] proxy/trojan: tunneling request to udp:8.8.8.8:53 via 192.168.31.2:1443
2023/04/01 09:06:19 [Debug] transport/internet/udp: ReadMultiBuffer end
sub4 case <-sub4.Wait():
2023/04/01 09:06:19 [Info] app/dns: UDP:8.8.8.8:53 got answer: www.cnn.com. TypeA -> [146.75.115.5] 12.178ms
2023/04/01 09:06:19 [Debug] app/dns: A
2023/04/01 09:06:19 [Debug] app/dns: UDP:8.8.8.8:53 updating IP records for domain:www.cnn.com.
2023/04/01 09:06:19 [Debug] app/dns: 1
2023/04/01 09:06:19 [Debug] app/dns: 2
2023/04/01 09:06:19 [Debug] app/dns: 3
2023/04/01 09:06:19 [Debug] app/dns: 4
2023/04/01 09:06:19 [Debug] app/dns: 5
2023/04/01 09:06:19 [Debug] app/dns: 6
2023/04/01 09:06:19 [Debug] app/dns: B
2023/04/01 09:06:19 [Debug] transport/internet/udp: handleInput...
2023/04/01 09:06:19 [Debug] transport/internet/udp: ReadMultiBuffer begin
2023/04/01 09:06:19 [Debug] transport/internet/udp: ReadMultiBuffer end
2023/04/01 09:06:19 [Info] app/dns: UDP:8.8.8.8:53 got answer: www.cnn.com. TypeAAAA -> [[2a04:4e42:1a::773]] 233.5629ms

server side log:

2023/04/01 01:05:37 [Warning] V2Ray 5.4.1 started
2023/04/01 01:06:19 [Info] [4070251905] proxy/trojan: firstLen = 148
2023/04/01 01:06:19 [Info] [4070251905] proxy/trojan: tunnelling request to udp:8.8.8.8:53
-- first A
2023/04/01 01:06:19 [Debug] [4070251905] transport/internet/udp: dispatch request to: udp:8.8.8.8:53
2023/04/01 01:06:19 [Info] transport/internet/udp: establishing new connection for udp:8.8.8.8:53
2023/04/01 01:06:19 [Info] [4070251905] proxy/trojan: tunnelling request to udp:8.8.8.8:53
2023/04/01 01:06:19 tcp:192.168.31.100:1618 accepted udp:8.8.8.8:53 [direct] email: love@v2fly.org
-- second AAAA
2023/04/01 01:06:19 [Debug] [4070251905] transport/internet/udp: dispatch request to: udp:8.8.8.8:53
2023/04/01 01:06:19 [Warning] [4070251905] app/dispatcher: default route for udp:8.8.8.8:53
2023/04/01 01:06:19 [Info] [4070251905] proxy/freedom: opening connection to udp:8.8.8.8:53
2023/04/01 01:06:19 [Info] [4239477395] proxy/trojan: firstLen = 170
2023/04/01 01:06:19 [Info] [4239477395] proxy/trojan: received request for tcp:www.cnn.com:80
2023/04/01 01:06:19 [Warning] [4239477395] app/dispatcher: default route for tcp:www.cnn.com:80
2023/04/01 01:06:19 [Info] [4239477395] proxy/freedom: opening connection to tcp:www.cnn.com:80
2023/04/01 01:06:19 [Info] [4239477395] transport/internet/tcp: dialing TCP to tcp:www.cnn.com:80
2023/04/01 01:06:19 192.168.31.100:1619 accepted tcp:www.cnn.com:80 [direct] email: love@v2fly.org
2023/04/01 01:06:20 [Info] [4239477395] app/proxyman/outbound: failed to process outbound traffic > proxy/freedom: connection ends > context canceled

got two dns response
图片

dyhkwong added a commit to dyhkwong/v2ray-core that referenced this issue Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants