sing-box
sing-box copied to clipboard
使用type为local的dns服务器无法使用tcp请求
操作系统
Linux
系统版本
Linux hytron 6.12.41+deb13-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.41-1 (2025-08-12) x86_64 GNU/Linux
安装类型
sing-box 原始命令行程序
如果您使用图形客户端程序,请提供该程序版本。
No response
版本
sing-box version 1.12.4
Environment: go1.25.0 linux/amd64
Tags: with_gvisor,with_quic,with_dhcp,with_wireguard,with_utls,with_acme,with_clash_api,with_tailscale
Revision: 980e96250bf693bb8400183d6a05665da8ad9d03
CGO: disabled
描述
Linux下可以在 /etc/resolv.conf里面指定 options来强制使用tcp来请求dns即使dns.Msg没有被Truncated。
nameserver 1.1.1.1
options usevc
sing-box 中会读取这个文件并且设置对应配置。
但是在使用了这个选项过后会直接超时,查看代码发现是在对 local DNS进行处理的时候,没有处理TCP的情况,只写入了消息,没有写入消息长度的头。
https://github.com/SagerNet/sing-box/blob/980e96250bf693bb8400183d6a05665da8ad9d03/dns/transport/local/local.go#L148-L204
同时这个bug也会导致遇到 Truncated的消息无法重新请求。
重现方式
/etc/resolv.conf
nameserver 1.1.1.1
options usevc
sing-box 配置
{
"log":{
"level":"trace"
},
"dns":{
"servers":[
{"tag":"internal","type":"local"}
],
"final":"internal"
},
"inbounds":[
{"type":"direct","tag":"dns-in","listen":"127.0.0.1","listen_port":20853}
],
"route":{
"rules":[
{
"inbound":["dns-in"],
"action":"hijack-dns"
}
]
},
"outbounds":[
{"tag":"direct","type":"direct","domain_resolver":"internal"}
]
}
使用 dig 来查询。
dig google.com @127.0.0.1 -p 20853 A
日志
INFO[0000] network: updated default interface ens18, index 2
INFO[0000] inbound/direct[dns-in]: tcp server started at 127.0.0.1:20853
INFO[0000] inbound/direct[dns-in]: udp server started at 127.0.0.1:20853
INFO[0000] inbound/mixed[mixed-in]: tcp server started at 127.0.0.1:20808
INFO[0000] sing-box started (0.00s)
INFO[0396] [2879948663 0ms] inbound/direct[dns-in]: inbound packet connection from 127.0.0.1:44539
INFO[0396] [2879948663 0ms] inbound/direct[dns-in]: inbound packet connection to 127.0.0.1:20853
DEBUG[0396] [2879948663 0ms] router: match[0] inbound=dns-in => hijack-dns
DEBUG[0396] [2879948663 0ms] dns: exchange google.com. IN A
INFO[0401] [2823685691 0ms] inbound/direct[dns-in]: inbound packet connection from 127.0.0.1:54277
INFO[0401] [2823685691 0ms] inbound/direct[dns-in]: inbound packet connection to 127.0.0.1:20853
DEBUG[0401] [2823685691 0ms] router: match[0] inbound=dns-in => hijack-dns
DEBUG[0401] [2823685691 0ms] dns: exchange google.com. IN A
ERROR[0406] [2879948663 10.0s] dns: exchange failed for google.com. IN A: context deadline exceeded
INFO[0406] [3969074882 0ms] inbound/direct[dns-in]: inbound packet connection from 127.0.0.1:36056
INFO[0406] [3969074882 0ms] inbound/direct[dns-in]: inbound packet connection to 127.0.0.1:20853
DEBUG[0406] [3969074882 0ms] router: match[0] inbound=dns-in => hijack-dns
DEBUG[0406] [3969074882 0ms] dns: exchange google.com. IN A
ERROR[0411] [2823685691 10.0s] dns: exchange failed for google.com. IN A: google.com.: read response: read tcp 45.196.220.82:36588->1.1.1.1:53: i/o timeout
ERROR[0416] [3969074882 10.0s] dns: exchange failed for google.com. IN A: context deadline exceeded
支持我们
- [ ] 我已经 赞助
完整性要求
- [x] 我保证阅读了文档,了解所有我编写的配置文件项的含义,而不是大量堆砌看似有用的选项或默认值。
- [x] 我保证提供了可以在本地重现该问题的服务器、客户端配置文件与流程,而不是一个脱敏的复杂客户端配置文件。
- [x] 我保证提供了可用于重现我报告的错误的最简配置,而不是依赖远程服务器、TUN、图形界面客户端或者其他闭源软件。
- [x] 我保证提供了完整的配置文件与日志,而不是出于对自身智力的自信而仅提供了部分认为有用的部分。
Could you check if this has been correctly fixed in the latest stable version?