XTLS / Xray-core

Xray, Penetrates Everything. Also the best v2ray-core, with XTLS support. Fully compatible configuration.
https://t.me/projectXray
Mozilla Public License 2.0
24.19k stars 3.8k forks source link

Windows下 xray 内部 DNS 第一次查询必定超时 #3504

Closed r06ertray closed 2 months ago

r06ertray commented 2 months ago

完整性要求

版本

Xray 1.8.16 9432a60 (go1.22.4 windows/amd64)

描述

在 Windows 10上,使用 xray 的dokodemo-door 监听本地 53 端口;在将流量发送给 xray 内部 DNS服务查询时,会出现超时卡顿问题。

重现方式

在 Widows 的 CMD 中,使用 nslookup 作 DNS 查询,会出现超时提示,如下:


nslookup google.com 127.0.0.1
DNS request timed out.
    timeout was 2 seconds.
服务器:  UnKnown
Address:  127.0.0.1

名称:    google.com
Addresses:  142.250.4.102
          142.250.4.113
          142.250.4.139
          142.250.4.138
          142.250.4.100
          142.250.4.101

nslookup youtube.com 127.0.0.1
DNS request timed out.
    timeout was 2 seconds.
服务器:  UnKnown
Address:  127.0.0.1

名称:    youtube.com
Addresses:  64.233.170.190
          64.233.170.91
          64.233.170.136
          64.233.170.93

注意, 1、如果将本地客户端中的 dns-in 直接路由到 proxy,则一切正常。 2、依次查询 google.com 和 youtube.com,服务端日志中只能看到一次 8.8.8.8 连接,不知为何。

客户端配置


{
    "log": {
        "loglevel": "debug",
        "dnsLog": true
    },
    "inbounds": [
        {
            "tag": "dns-in",
            "port": 53,
            "address": "127.0.0.1",
            "protocol": "dokodemo-door",
            "settings": {
                "address": "1.1.1.1",
                "port": 53,
                "network": "udp"
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom"
        },
        {
            "tag": "dns-out",
            "protocol": "dns"
        },
        {
            "tag": "proxy",
            "......"
        }
    ],
    "dns": {
        "servers": [
            "8.8.8.8"
        ],
        "queryStrategy": "UseIPv4",
        "disableCache": true,
        "disableFallback": true
    },
    "routing": {
        "domainStrategy": "IPOnDemand",
        "rules": [
            {
                "type": "field",
                "outboundTag": "dns-out",
                "inboundTag": [
                    "dns-in"
                ]
            },
            {
                "type": "field",
                "outboundTag": "proxy",
                "ip": [
                    "1.1.1.1",
                    "8.8.4.4",
                    "8.8.8.8"
                ]
            }
        ]
    }
}                                                                                                    

客户端日志

域名替换成了 host.domain.com


Xray 1.8.16 (Xray, Penetrates Everything.) 9432a60 (go1.22.4 windows/amd64)                                                                                                         
A unified platform for anti-censorship.                                                                                                                                             
2024/07/04 19:33:54 [Info] infra/conf/serial: Reading config: ..\config.json                                                                                                        
2024/07/04 19:33:54 [Debug] app/log: Logger started                                                                                                                                 
2024/07/04 19:33:54 [Info] app/dns: DNS: created UDP client initialized for 8.8.8.8:53                                                                                              
2024/07/04 19:33:54 [Info] transport/internet/udp: listening UDP on 0.0.0.0:53                                                                                                      
2024/07/04 19:33:54 [Warning] core: Xray 1.8.16 started                                                                                                                             
2024/07/04 19:34:07 [Debug] [2614891948] proxy/dokodemo: processing connection from: 127.0.0.1:49933                                                                                
2024/07/04 19:34:07 [Info] [2614891948] proxy/dokodemo: received request for 127.0.0.1:49933                                                                                        
2024/07/04 19:34:07 [Info] [2614891948] app/dispatcher: taking detour [dns-out] for [udp:1.1.1.1:53]                                                                                
2024/07/04 19:34:07 [Info] [2614891948] proxy/dns: handling DNS traffic to udp:1.1.1.1:53                                                                                           
2024/07/04 19:34:07 127.0.0.1:49933 accepted udp:1.1.1.1:53 [dns-in -> dns-out]                                                                                                     
2024/07/04 19:34:09 [Debug] [4102608995] proxy/dokodemo: processing connection from: 127.0.0.1:49937                                                                                
2024/07/04 19:34:09 [Info] [4102608995] proxy/dokodemo: received request for 127.0.0.1:49937                                                                                        
2024/07/04 19:34:09 [Info] [4102608995] app/dispatcher: taking detour [dns-out] for [udp:1.1.1.1:53]                                                                                
2024/07/04 19:34:09 [Info] [4102608995] proxy/dns: handling DNS traffic to udp:1.1.1.1:53                                                                                           
2024/07/04 19:34:09 127.0.0.1:49937 accepted udp:1.1.1.1:53 [dns-in -> dns-out]                                                                                                     
2024/07/04 19:34:09 [Debug] app/dns: domain google.com will use the first DNS: [UDP:8.8.8.8:53]                                                                                     
2024/07/04 19:34:09 [Debug] app/dns: DNS cache is disabled. Querying IP for google.com at UDP:8.8.8.8:53                                                                            
2024/07/04 19:34:09 [Debug] app/dns: UDP:8.8.8.8:53 querying DNS for: google.com.                                                                                                   
2024/07/04 19:34:09 [Debug] transport/internet/udp: dispatch request to: udp:8.8.8.8:53                                                                                             
2024/07/04 19:34:09 [Info] transport/internet/udp: establishing new connection for udp:8.8.8.8:53                                                                                   
2024/07/04 19:34:09 [Info] app/dispatcher: taking detour [proxy] for [udp:8.8.8.8:53]                                                                                               
2024/07/04 19:34:09 [Info] transport/internet/grpc: creating connection to tcp:host.domain.com:443                                                                                  
2024/07/04 19:34:09 [Debug] transport/internet/grpc: using gRPC tun mode service name: `5e057e37fbf` stream name: `Tun`                                                                   
2024/07/04 19:34:09 [Debug] transport/internet: dialing to tcp:host.domain.com:443                                                                                                  
2024/07/04 19:34:09 DNS accepted udp:8.8.8.8:53 [xray.system.fa49d224-e6a9-4a12-9f1b-7f7308e8b48e -> proxy]                                                                         
2024/07/04 19:34:09 [Info] proxy/trojan: tunneling request to udp:8.8.8.8:53 via host.domain.com:443                                                                                
2024/07/04 19:34:09 [Info] app/dns: UDP:8.8.8.8:53 got answer: google.com. TypeA -> [142.250.4.102 142.250.4.113 142.250.4.139 142.250.4.138 142.250.4.100 142.250.4.101] 344.0596ms
2024/07/04 19:34:09 [Debug] app/dns: UDP:8.8.8.8:53 updating IP records for domain:google.com.                                                                                      
2024/07/04 19:34:09 [Debug] [1100131740] proxy/dokodemo: processing connection from: 127.0.0.1:49938                                                                                
2024/07/04 19:34:09 [Info] [1100131740] proxy/dokodemo: received request for 127.0.0.1:49938                                                                                        
2024/07/04 19:34:09 [Info] [1100131740] app/dispatcher: taking detour [dns-out] for [udp:1.1.1.1:53]                                                                                
2024/07/04 19:34:09 [Info] [1100131740] proxy/dns: handling DNS traffic to udp:1.1.1.1:53                                                                                           
2024/07/04 19:34:09 UDP:8.8.8.8:53 got answer: google.com -> [142.250.4.102, 142.250.4.113, 142.250.4.139, 142.250.4.138, 142.250.4.100, 142.250.4.101] 344.0596ms                  
2024/07/04 19:34:09 127.0.0.1:49938 accepted udp:1.1.1.1:53 [dns-in -> dns-out]                                                                                                     
2024/07/04 19:34:21 [Debug] [2270294573] proxy/dokodemo: processing connection from: 127.0.0.1:55792                                                                                
2024/07/04 19:34:21 [Info] [2270294573] proxy/dokodemo: received request for 127.0.0.1:55792                                                                                        
2024/07/04 19:34:21 [Info] [2270294573] app/dispatcher: taking detour [dns-out] for [udp:1.1.1.1:53]                                                                                
2024/07/04 19:34:21 [Info] [2270294573] proxy/dns: handling DNS traffic to udp:1.1.1.1:53                                                                                           
2024/07/04 19:34:21 127.0.0.1:55792 accepted udp:1.1.1.1:53 [dns-in -> dns-out]                                                                                                     
2024/07/04 19:34:23 [Debug] [3206188657] proxy/dokodemo: processing connection from: 127.0.0.1:55793                                                                                
2024/07/04 19:34:23 [Info] [3206188657] proxy/dokodemo: received request for 127.0.0.1:55793                                                                                        
2024/07/04 19:34:23 [Info] [3206188657] app/dispatcher: taking detour [dns-out] for [udp:1.1.1.1:53]                                                                                
2024/07/04 19:34:23 [Info] [3206188657] proxy/dns: handling DNS traffic to udp:1.1.1.1:53                                                                                           
2024/07/04 19:34:23 [Debug] app/dns: domain youtube.com will use the first DNS: [UDP:8.8.8.8:53]                                                                                    
2024/07/04 19:34:23 [Debug] app/dns: DNS cache is disabled. Querying IP for youtube.com at UDP:8.8.8.8:53                                                                           
2024/07/04 19:34:23 [Debug] app/dns: UDP:8.8.8.8:53 querying DNS for: youtube.com.                                                                                                  
2024/07/04 19:34:23 [Debug] transport/internet/udp: dispatch request to: udp:8.8.8.8:53                                                                                             
2024/07/04 19:34:23 127.0.0.1:55793 accepted udp:1.1.1.1:53 [dns-in -> dns-out]                                                                                                     
2024/07/04 19:34:23 [Info] app/dns: UDP:8.8.8.8:53 got answer: youtube.com. TypeA -> [64.233.170.190 64.233.170.91 64.233.170.136 64.233.170.93] 81.3091ms                          
2024/07/04 19:34:23 [Debug] app/dns: UDP:8.8.8.8:53 updating IP records for domain:youtube.com.                                                                                     
2024/07/04 19:34:23 [Debug] [2943809040] proxy/dokodemo: processing connection from: 127.0.0.1:55794                                                                                
2024/07/04 19:34:23 [Info] [2943809040] proxy/dokodemo: received request for 127.0.0.1:55794                                                                                        
2024/07/04 19:34:23 [Info] [2943809040] app/dispatcher: taking detour [dns-out] for [udp:1.1.1.1:53]                                                                                
2024/07/04 19:34:23 [Info] [2943809040] proxy/dns: handling DNS traffic to udp:1.1.1.1:53                                                                                           
2024/07/04 19:34:23 UDP:8.8.8.8:53 got answer: youtube.com -> [64.233.170.190, 64.233.170.91, 64.233.170.136, 64.233.170.93] 81.3091ms                                              
2024/07/04 19:34:23 127.0.0.1:55794 accepted udp:1.1.1.1:53 [dns-in -> dns-out]                                                                                                     
HeXis-YS commented 2 months ago

这应该是预期的行为,对于非IP的DNS查询默认会丢弃。 在DNS出站中添加"nonIPQuery": "skip"可以解决这个问题。 参考文档

r06ertray commented 2 months ago

这应该是预期的行为,对于非IP的DNS查询默认会丢弃。 在DNS出站中添加"nonIPQuery": "skip"可以解决这个问题。 参考文档

1、添加 "nonIPQuery": "skip" 后还是会出现 DNS request timed out.\n timeout was 2 seconds提示。

2、下面这个配置文件更简单,直接使用可以复现问题


{
    "log": {
        "loglevel": "debug",
        "dnsLog": true
    },
    "inbounds": [
        {
            "tag": "dns-in",
            "port": 53,
            "address": "127.0.0.1",
            "protocol": "dokodemo-door",
            "settings": {
                "network": "udp",
                "address": "114.114.114.114",
                "port": 53
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom"
        },
        {
            "tag": "dns-out",
            "protocol": "dns",
            "nonIPQuery": "skip"
        }
    ],
    "dns": {
        "servers": [
            "114.114.114.114"
        ],
        "queryStrategy": "UseIPv4",
        "disableCache": true
    },
    "routing": {
        "domainStrategy": "IPOnDemand",
        "rules": [
            {
                "type": "field",
                "outboundTag": "dns-out",
                "inboundTag": [
                    "dns-in"
                ]
            }
        ]
    }
}
HeXis-YS commented 2 months ago

应该把"nonIPQuery": "skip"加到settings中。

{
    "log": {
        "loglevel": "debug",
        "dnsLog": true
    },
    "inbounds": [
        {
            "tag": "dns-in",
            "port": 53,
            "address": "127.0.0.1",
            "protocol": "dokodemo-door",
            "settings": {
                "network": "udp",
                "address": "114.114.114.114",
                "port": 53
            }
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom"
        },
        {
            "tag": "dns-out",
            "protocol": "dns",
            "settings": {
                "nonIPQuery": "skip"
            }
        }
    ],
    "dns": {
        "servers": [
            "114.114.114.114"
        ],
        "queryStrategy": "UseIPv4",
        "disableCache": true
    },
    "routing": {
        "domainStrategy": "IPOnDemand",
        "rules": [
            {
                "type": "field",
                "outboundTag": "dns-out",
                "inboundTag": [
                    "dns-in"
                ]
            }
        ]
    }
}
r06ertray commented 2 months ago

OK