Skip to content

Commit f24a2ae

Browse files
committed
Add support for client-subnet DNS options
1 parent 0517cee commit f24a2ae

File tree

18 files changed

+313
-137
lines changed

18 files changed

+313
-137
lines changed

adapter/router.go

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type DNSRule interface {
8686
Rule
8787
DisableCache() bool
8888
RewriteTTL() *uint32
89+
ClientSubnet() *netip.Addr
8990
WithAddressLimit() bool
9091
MatchAddressLimit(metadata *InboundContext) bool
9192
}

docs/configuration/dns/index.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
---
2+
icon: material/new-box
3+
---
4+
5+
!!! quote "Changes in sing-box 1.9.0"
6+
7+
:material-plus: [client_subnet](#client_subnet)
8+
19
# DNS
210

311
### Structure
@@ -13,6 +21,7 @@
1321
"disable_expire": false,
1422
"independent_cache": false,
1523
"reverse_mapping": false,
24+
"client_subnet": "",
1625
"fakeip": {}
1726
}
1827
}
@@ -60,6 +69,10 @@ Stores a reverse mapping of IP addresses after responding to a DNS query in orde
6069
Since this process relies on the act of resolving domain names by an application before making a request, it can be
6170
problematic in environments such as macOS, where DNS is proxied and cached by the system.
6271

63-
#### fakeip
72+
#### client_subnet
73+
74+
!!! question "Since sing-box 1.9.0"
75+
76+
Append a `edns0-subnet` OPT extra record with the specified IP address to every query by default.
6477

65-
[FakeIP](./fakeip/) settings.
78+
Can be overrides by `servers.[].client_subnet` or `rules.[].client_subnet`.

docs/configuration/dns/index.zh.md

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
---
2+
icon: material/new-box
3+
---
4+
5+
!!! quote "sing-box 1.9.0 中的更改"
6+
7+
:material-plus: [client_subnet](#client_subnet)
8+
19
# DNS
210

311
### 结构
@@ -13,6 +21,7 @@
1321
"disable_expire": false,
1422
"independent_cache": false,
1523
"reverse_mapping": false,
24+
"client_subnet": "",
1625
"fakeip": {}
1726
}
1827
}
@@ -58,6 +67,14 @@
5867

5968
由于此过程依赖于应用程序在发出请求之前解析域名的行为,因此在 macOS 等 DNS 由系统代理和缓存的环境中可能会出现问题。
6069

70+
#### client_subnet
71+
72+
!!! question "自 sing-box 1.9.0 起"
73+
74+
默认情况下,将带有指定 IP 地址的 `edns0-subnet` OPT 附加记录附加到每个查询。
75+
76+
可以被 `servers.[].client_subnet``rules.[].client_subnet` 覆盖。
77+
6178
#### fakeip
6279

6380
[FakeIP](./fakeip/) 设置。

docs/configuration/dns/rule.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ icon: material/new-box
66

77
:material-plus: [geoip](#geoip)
88
:material-plus: [ip_cidr](#ip_cidr)
9-
:material-plus: [ip_is_private](#ip_is_private)
9+
:material-plus: [ip_is_private](#ip_is_private)
10+
:material-plus: [client_subnet](#client_subnet)
1011

1112
!!! quote "Changes in sing-box 1.8.0"
1213

@@ -121,15 +122,17 @@ icon: material/new-box
121122
],
122123
"server": "local",
123124
"disable_cache": false,
124-
"rewrite_ttl": 100
125+
"rewrite_ttl": 100,
126+
"client_subnet": "127.0.0.1"
125127
},
126128
{
127129
"type": "logical",
128130
"mode": "and",
129131
"rules": [],
130132
"server": "local",
131133
"disable_cache": false,
132-
"rewrite_ttl": 100
134+
"rewrite_ttl": 100,
135+
"client_subnet": "127.0.0.1"
133136
}
134137
]
135138
}
@@ -280,8 +283,6 @@ Match Clash mode.
280283

281284
#### wifi_ssid
282285

283-
<!-- md:version 1.7.0-beta.4 -->
284-
285286
!!! quote ""
286287

287288
Only supported in graphical clients on Android and iOS.
@@ -326,6 +327,14 @@ Disable cache and save cache in this query.
326327

327328
Rewrite TTL in DNS responses.
328329

330+
#### client_subnet
331+
332+
!!! question "Since sing-box 1.9.0"
333+
334+
Append a `edns0-subnet` OPT extra record with the specified IP address to every query by default.
335+
336+
Will overrides `dns.client_subnet` and `servers.[].client_subnet`.
337+
329338
### Address Filter Fields
330339

331340
Only takes effect for IP address requests. When the query results do not match the address filtering rule items, the current rule will be skipped.

docs/configuration/dns/rule.zh.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ icon: material/new-box
66

77
:material-plus: [geoip](#geoip)
88
:material-plus: [ip_cidr](#ip_cidr)
9-
:material-plus: [ip_is_private](#ip_is_private)
9+
:material-plus: [ip_is_private](#ip_is_private)
10+
:material-plus: [client_subnet](#client_subnet)
1011

1112
!!! quote "sing-box 1.8.0 中的更改"
1213

@@ -120,14 +121,16 @@ icon: material/new-box
120121
"direct"
121122
],
122123
"server": "local",
123-
"disable_cache": false
124+
"disable_cache": false,
125+
"client_subnet": "127.0.0.1"
124126
},
125127
{
126128
"type": "logical",
127129
"mode": "and",
128130
"rules": [],
129131
"server": "local",
130-
"disable_cache": false
132+
"disable_cache": false,
133+
"client_subnet": "127.0.0.1"
131134
}
132135
]
133136
}
@@ -322,6 +325,14 @@ DNS 查询类型。值可以为整数或者类型名称字符串。
322325

323326
重写 DNS 回应中的 TTL。
324327

328+
#### client_subnet
329+
330+
!!! question "自 sing-box 1.9.0 起"
331+
332+
默认情况下,将带有指定 IP 地址的 `edns0-subnet` OPT 附加记录附加到每个查询。
333+
334+
将覆盖 `dns.client_subnet``servers.[].client_subnet`
335+
325336
### 地址筛选字段
326337

327338
仅对IP地址请求生效。 当查询结果与地址筛选规则项不匹配时,将跳过当前规则。

docs/configuration/dns/server.md

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1+
---
2+
icon: material/new-box
3+
---
4+
5+
!!! quote "Changes in sing-box 1.9.0"
6+
7+
:material-plus: [client_subnet](#client_subnet)
8+
19
### Structure
210

311
```json
412
{
513
"dns": {
614
"servers": [
715
{
8-
"tag": "google",
9-
"address": "tls://dns.google",
10-
"address_resolver": "local",
11-
"address_strategy": "prefer_ipv4",
12-
"strategy": "ipv4_only",
13-
"detour": "direct"
16+
"tag": "",
17+
"address": "",
18+
"address_resolver": "",
19+
"address_strategy": "",
20+
"strategy": "",
21+
"detour": "",
22+
"client_subnet": ""
1423
}
1524
]
1625
}
1726
}
18-
1927
```
2028

2129
### Fields
@@ -80,10 +88,20 @@ Default domain strategy for resolving the domain names.
8088

8189
One of `prefer_ipv4` `prefer_ipv6` `ipv4_only` `ipv6_only`.
8290

83-
Take no effect if override by other settings.
91+
Take no effect if overridden by other settings.
8492

8593
#### detour
8694

8795
Tag of an outbound for connecting to the dns server.
8896

8997
Default outbound will be used if empty.
98+
99+
#### client_subnet
100+
101+
!!! question "Since sing-box 1.9.0"
102+
103+
Append a `edns0-subnet` OPT extra record with the specified IP address to every query by default.
104+
105+
Can be overrides by `rules.[].client_subnet`.
106+
107+
Will overrides `dns.client_subnet`.

docs/configuration/dns/server.zh.md

+25-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1+
---
2+
icon: material/new-box
3+
---
4+
5+
!!! quote "sing-box 1.9.0 中的更改"
6+
7+
:material-plus: [client_subnet](#client_subnet)
8+
19
### 结构
210

311
```json
412
{
513
"dns": {
614
"servers": [
715
{
8-
"tag": "google",
9-
"address": "tls://dns.google",
10-
"address_resolver": "local",
11-
"address_strategy": "prefer_ipv4",
12-
"strategy": "ipv4_only",
13-
"detour": "direct"
16+
"tag": "",
17+
"address": "",
18+
"address_resolver": "",
19+
"address_strategy": "",
20+
"strategy": "",
21+
"detour": "",
22+
"client_subnet": ""
1423
}
1524
]
1625
}
1726
}
18-
1927
```
2028

2129
### 字段
@@ -87,3 +95,13 @@ DNS 服务器的地址。
8795
用于连接到 DNS 服务器的出站的标签。
8896

8997
如果为空,将使用默认出站。
98+
99+
#### client_subnet
100+
101+
!!! question "自 sing-box 1.9.0 起"
102+
103+
默认情况下,将带有指定 IP 地址的 `edns0-subnet` OPT 附加记录附加到每个查询。
104+
105+
可以被 `rules.[].client_subnet` 覆盖。
106+
107+
将覆盖 `dns.client_subnet`

0 commit comments

Comments
 (0)