[Feature Request] Tun 模式并启用 auto_redirect 时,希望增加一个选项用于控制 DNS 劫持范围
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 38.2k
- Forks
- 4.6k
- Avg merge
- 19d 15h
- Merged PRs (30d)
- 1
Description
在 Tun 模式并开启 auto_redirect 时,sing-box 会自动创建 nftables 规则,对 DNS 流量(TCP/UDP 53 端口)进行劫持。
目前规则会匹配来源 IP 属于以下集合的流量:
- inet4_local_address_set
- inet6_local_address_set
sing-box 自动生成的规则类似:
ip saddr @inet4_local_address_set meta l4proto { tcp, udp } th dport 53 dnat ip to ...
当前行为
inet4_local_address_set 和 inet6_local_address_set 是 sing-box 自动创建并填充的集合,其中不仅包含 loopback 地址,还包含当前机器检测到的局域网网段。
set inet4_local_address_set {
type ipv4_addr
flags interval
elements = {
127.0.0.0/8,
172.19.0.0/30,
192.168.X.0/24
}
}
set inet6_local_address_set {
type ipv6_addr
flags interval
elements = {
::1,
240e:XXXX::/64,
fdfe:dcba:9876::/126
}
}
因此,当该设备作为旁路由使用时,来自局域网的 53 普通流量请求也会被自动劫持。
在某些使用场景中,希望只劫持 本机发出的 DNS 请求,而不希望影响局域网设备转发来的的 53 端口流量。
当前的实现会同时匹配:
- 本机流量
- 局域网流量
这在网关或旁路由场景下可能不是期望行为。
期望功能
希望能够增加一个可选配置,用于控制 DNS 劫持的范围,例如只劫持 本机 DNS 请求。
新增一个类似选项:
auto_redirect_dns_local_only: true
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the Tun-mode auto_redirect nftables rule generation and the inet4_local_address_set and inet6_local_address_set handling described in the issue. Trace how DNS TCP/UDP port 53 rules are assembled and how configuration options are defined and tested. Done means the new option can restrict interception to local DNS requests without affecting forwarded LAN traffic, with coverage for both enabled and default behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- networking
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100