2023-12-01 13:24:18 +08:00
|
|
|
---
|
2024-02-03 17:45:27 +08:00
|
|
|
icon: material/new-box
|
2023-12-01 13:24:18 +08:00
|
|
|
---
|
|
|
|
|
2024-02-03 17:45:27 +08:00
|
|
|
!!! quote "sing-box 1.9.0 中的更改"
|
|
|
|
|
|
|
|
:material-plus: [geoip](#geoip)
|
|
|
|
:material-plus: [ip_cidr](#ip_cidr)
|
2024-02-09 18:37:25 +08:00
|
|
|
:material-plus: [ip_is_private](#ip_is_private)
|
|
|
|
:material-plus: [client_subnet](#client_subnet)
|
2024-02-03 17:45:27 +08:00
|
|
|
|
2023-12-01 13:24:18 +08:00
|
|
|
!!! quote "sing-box 1.8.0 中的更改"
|
|
|
|
|
|
|
|
:material-plus: [rule_set](#rule_set)
|
|
|
|
:material-plus: [source_ip_is_private](#source_ip_is_private)
|
|
|
|
:material-delete-clock: [geoip](#geoip)
|
|
|
|
:material-delete-clock: [geosite](#geosite)
|
|
|
|
|
2022-08-24 16:23:21 +08:00
|
|
|
### 结构
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"dns": {
|
|
|
|
"rules": [
|
|
|
|
{
|
|
|
|
"inbound": [
|
|
|
|
"mixed-in"
|
|
|
|
],
|
|
|
|
"ip_version": 6,
|
2023-02-08 16:18:40 +08:00
|
|
|
"query_type": [
|
|
|
|
"A",
|
|
|
|
"HTTPS",
|
|
|
|
32768
|
|
|
|
],
|
2022-08-24 16:23:21 +08:00
|
|
|
"network": "tcp",
|
|
|
|
"auth_user": [
|
|
|
|
"usera",
|
|
|
|
"userb"
|
|
|
|
],
|
|
|
|
"protocol": [
|
|
|
|
"tls",
|
|
|
|
"http",
|
|
|
|
"quic"
|
|
|
|
],
|
|
|
|
"domain": [
|
|
|
|
"test.com"
|
|
|
|
],
|
|
|
|
"domain_suffix": [
|
|
|
|
".cn"
|
|
|
|
],
|
|
|
|
"domain_keyword": [
|
|
|
|
"test"
|
|
|
|
],
|
|
|
|
"domain_regex": [
|
|
|
|
"^stun\\..+"
|
|
|
|
],
|
|
|
|
"geosite": [
|
|
|
|
"cn"
|
|
|
|
],
|
|
|
|
"source_geoip": [
|
|
|
|
"private"
|
|
|
|
],
|
2024-02-03 17:45:27 +08:00
|
|
|
"geoip": [
|
|
|
|
"cn"
|
|
|
|
],
|
2022-08-24 16:23:21 +08:00
|
|
|
"source_ip_cidr": [
|
2024-02-03 17:45:27 +08:00
|
|
|
"10.0.0.0/24",
|
|
|
|
"192.168.0.1"
|
2022-08-24 16:23:21 +08:00
|
|
|
],
|
2023-12-01 13:24:18 +08:00
|
|
|
"source_ip_is_private": false,
|
2024-02-03 17:45:27 +08:00
|
|
|
"ip_cidr": [
|
|
|
|
"10.0.0.0/24",
|
|
|
|
"192.168.0.1"
|
|
|
|
],
|
|
|
|
"ip_is_private": false,
|
2022-08-24 16:23:21 +08:00
|
|
|
"source_port": [
|
|
|
|
12345
|
|
|
|
],
|
|
|
|
"source_port_range": [
|
|
|
|
"1000:2000",
|
|
|
|
":3000",
|
|
|
|
"4000:"
|
|
|
|
],
|
|
|
|
"port": [
|
|
|
|
80,
|
|
|
|
443
|
|
|
|
],
|
|
|
|
"port_range": [
|
|
|
|
"1000:2000",
|
|
|
|
":3000",
|
|
|
|
"4000:"
|
|
|
|
],
|
|
|
|
"process_name": [
|
|
|
|
"curl"
|
|
|
|
],
|
2022-08-31 14:33:52 +08:00
|
|
|
"process_path": [
|
|
|
|
"/usr/bin/curl"
|
|
|
|
],
|
2022-08-24 16:23:21 +08:00
|
|
|
"package_name": [
|
|
|
|
"com.termux"
|
|
|
|
],
|
|
|
|
"user": [
|
|
|
|
"sekai"
|
|
|
|
],
|
|
|
|
"user_id": [
|
|
|
|
1000
|
|
|
|
],
|
2022-09-10 22:42:20 +08:00
|
|
|
"clash_mode": "direct",
|
2023-11-09 17:04:08 +08:00
|
|
|
"wifi_ssid": [
|
|
|
|
"My WIFI"
|
|
|
|
],
|
|
|
|
"wifi_bssid": [
|
|
|
|
"00:00:00:00:00:00"
|
|
|
|
],
|
2023-12-01 13:24:18 +08:00
|
|
|
"rule_set": [
|
|
|
|
"geoip-cn",
|
|
|
|
"geosite-cn"
|
|
|
|
],
|
2022-08-24 16:23:21 +08:00
|
|
|
"invert": false,
|
|
|
|
"outbound": [
|
|
|
|
"direct"
|
|
|
|
],
|
|
|
|
"server": "local",
|
2024-02-09 18:37:25 +08:00
|
|
|
"disable_cache": false,
|
|
|
|
"client_subnet": "127.0.0.1"
|
2022-08-24 16:23:21 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"type": "logical",
|
|
|
|
"mode": "and",
|
|
|
|
"rules": [],
|
|
|
|
"server": "local",
|
2024-02-09 18:37:25 +08:00
|
|
|
"disable_cache": false,
|
|
|
|
"client_subnet": "127.0.0.1"
|
2022-08-24 16:23:21 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
!!! note ""
|
|
|
|
|
|
|
|
当内容只有一项时,可以忽略 JSON 数组 [] 标签
|
|
|
|
|
|
|
|
### 默认字段
|
|
|
|
|
|
|
|
!!! note ""
|
|
|
|
|
|
|
|
默认规则使用以下匹配逻辑:
|
|
|
|
(`domain` || `domain_suffix` || `domain_keyword` || `domain_regex` || `geosite`) &&
|
2022-09-14 22:03:26 +08:00
|
|
|
(`port` || `port_range`) &&
|
2023-12-01 13:24:18 +08:00
|
|
|
(`source_geoip` || `source_ip_cidr` || `source_ip_is_private`) &&
|
2022-09-14 22:03:26 +08:00
|
|
|
(`source_port` || `source_port_range`) &&
|
|
|
|
`other fields`
|
2022-08-24 16:23:21 +08:00
|
|
|
|
2023-12-01 13:24:18 +08:00
|
|
|
另外,引用的规则集可视为被合并,而不是作为一个单独的规则子项。
|
|
|
|
|
2022-08-24 16:23:21 +08:00
|
|
|
#### inbound
|
|
|
|
|
2023-12-14 22:23:52 +08:00
|
|
|
[入站](/zh/configuration/inbound/) 标签.
|
2022-08-24 16:23:21 +08:00
|
|
|
|
|
|
|
#### ip_version
|
|
|
|
|
|
|
|
4 (A DNS 查询) 或 6 (AAAA DNS 查询)。
|
|
|
|
|
2022-08-25 09:45:22 +08:00
|
|
|
默认不限制。
|
2022-08-24 16:23:21 +08:00
|
|
|
|
2023-02-08 16:18:40 +08:00
|
|
|
#### query_type
|
|
|
|
|
|
|
|
DNS 查询类型。值可以为整数或者类型名称字符串。
|
|
|
|
|
2022-08-24 16:23:21 +08:00
|
|
|
#### network
|
|
|
|
|
|
|
|
`tcp` 或 `udp`。
|
|
|
|
|
|
|
|
#### auth_user
|
|
|
|
|
|
|
|
认证用户名,参阅入站设置。
|
|
|
|
|
|
|
|
#### protocol
|
|
|
|
|
|
|
|
探测到的协议, 参阅 [协议探测](/zh/configuration/route/sniff/)。
|
|
|
|
|
|
|
|
#### domain
|
|
|
|
|
2022-08-24 16:56:29 +08:00
|
|
|
匹配完整域名。
|
2022-08-24 16:23:21 +08:00
|
|
|
|
|
|
|
#### domain_suffix
|
|
|
|
|
|
|
|
匹配域名后缀。
|
|
|
|
|
|
|
|
#### domain_keyword
|
|
|
|
|
|
|
|
匹配域名关键字。
|
|
|
|
|
|
|
|
#### domain_regex
|
|
|
|
|
|
|
|
匹配域名正则表达式。
|
|
|
|
|
|
|
|
#### geosite
|
|
|
|
|
2023-12-01 13:24:18 +08:00
|
|
|
!!! failure "已在 sing-box 1.8.0 废弃"
|
|
|
|
|
2023-12-03 14:53:22 +08:00
|
|
|
Geosite 已废弃且可能在不久的将来移除,参阅 [迁移指南](/zh/migration/#geosite)。
|
2023-12-01 13:24:18 +08:00
|
|
|
|
|
|
|
匹配 Geosite。
|
2022-08-24 16:23:21 +08:00
|
|
|
|
|
|
|
#### source_geoip
|
|
|
|
|
2023-12-01 13:24:18 +08:00
|
|
|
!!! failure "已在 sing-box 1.8.0 废弃"
|
|
|
|
|
2023-12-03 14:53:22 +08:00
|
|
|
GeoIP 已废弃且可能在不久的将来移除,参阅 [迁移指南](/zh/migration/#geoip)。
|
2023-12-01 13:24:18 +08:00
|
|
|
|
2022-08-24 16:23:21 +08:00
|
|
|
匹配源 GeoIP。
|
|
|
|
|
|
|
|
#### source_ip_cidr
|
|
|
|
|
|
|
|
匹配源 IP CIDR。
|
|
|
|
|
2023-12-01 13:24:18 +08:00
|
|
|
#### source_ip_is_private
|
|
|
|
|
|
|
|
!!! question "自 sing-box 1.8.0 起"
|
|
|
|
|
|
|
|
匹配非公开源 IP。
|
|
|
|
|
2022-08-24 16:23:21 +08:00
|
|
|
#### source_port
|
|
|
|
|
|
|
|
匹配源端口。
|
|
|
|
|
|
|
|
#### source_port_range
|
|
|
|
|
|
|
|
匹配源端口范围。
|
|
|
|
|
|
|
|
#### port
|
|
|
|
|
|
|
|
匹配端口。
|
|
|
|
|
|
|
|
#### port_range
|
|
|
|
|
|
|
|
匹配端口范围。
|
|
|
|
|
|
|
|
#### process_name
|
|
|
|
|
2023-11-09 17:04:08 +08:00
|
|
|
!!! quote ""
|
2022-08-24 16:23:21 +08:00
|
|
|
|
2022-08-25 09:45:22 +08:00
|
|
|
仅支持 Linux、Windows 和 macOS.
|
2022-08-24 16:23:21 +08:00
|
|
|
|
|
|
|
匹配进程名称。
|
|
|
|
|
2022-08-31 14:33:52 +08:00
|
|
|
#### process_path
|
|
|
|
|
2023-11-09 17:04:08 +08:00
|
|
|
!!! quote ""
|
2022-08-31 14:33:52 +08:00
|
|
|
|
|
|
|
仅支持 Linux、Windows 和 macOS.
|
|
|
|
|
|
|
|
匹配进程路径。
|
|
|
|
|
2022-08-24 16:23:21 +08:00
|
|
|
#### package_name
|
|
|
|
|
|
|
|
匹配 Android 应用包名。
|
|
|
|
|
|
|
|
#### user
|
|
|
|
|
2023-11-09 17:04:08 +08:00
|
|
|
!!! quote ""
|
2022-08-24 16:23:21 +08:00
|
|
|
|
2022-08-25 09:45:22 +08:00
|
|
|
仅支持 Linux。
|
2022-08-24 16:23:21 +08:00
|
|
|
|
|
|
|
匹配用户名。
|
|
|
|
|
|
|
|
#### user_id
|
|
|
|
|
2023-11-09 17:04:08 +08:00
|
|
|
!!! quote ""
|
2022-08-24 16:23:21 +08:00
|
|
|
|
2022-08-25 09:45:22 +08:00
|
|
|
仅支持 Linux。
|
2022-08-24 16:23:21 +08:00
|
|
|
|
|
|
|
匹配用户 ID。
|
|
|
|
|
2022-09-10 22:42:20 +08:00
|
|
|
#### clash_mode
|
|
|
|
|
|
|
|
匹配 Clash 模式。
|
|
|
|
|
2023-11-09 17:04:08 +08:00
|
|
|
#### wifi_ssid
|
|
|
|
|
|
|
|
!!! quote ""
|
|
|
|
|
|
|
|
仅在 Android 与 iOS 的图形客户端中支持。
|
|
|
|
|
|
|
|
匹配 WiFi SSID。
|
|
|
|
|
|
|
|
#### wifi_bssid
|
|
|
|
|
|
|
|
!!! quote ""
|
|
|
|
|
|
|
|
仅在 Android 与 iOS 的图形客户端中支持。
|
|
|
|
|
|
|
|
匹配 WiFi BSSID。
|
|
|
|
|
2023-12-01 13:24:18 +08:00
|
|
|
#### rule_set
|
|
|
|
|
|
|
|
!!! question "自 sing-box 1.8.0 起"
|
|
|
|
|
|
|
|
匹配[规则集](/zh/configuration/route/#rule_set)。
|
|
|
|
|
2022-08-24 16:23:21 +08:00
|
|
|
#### invert
|
|
|
|
|
|
|
|
反选匹配结果。
|
|
|
|
|
|
|
|
#### outbound
|
|
|
|
|
|
|
|
匹配出站。
|
|
|
|
|
2023-03-29 10:30:31 +08:00
|
|
|
`any` 可作为值用于匹配任意出站。
|
|
|
|
|
2022-08-24 16:23:21 +08:00
|
|
|
#### server
|
|
|
|
|
2022-08-24 18:43:39 +08:00
|
|
|
==必填==
|
2022-08-24 16:23:21 +08:00
|
|
|
|
|
|
|
目标 DNS 服务器的标签。
|
|
|
|
|
|
|
|
#### disable_cache
|
|
|
|
|
2022-08-25 09:45:22 +08:00
|
|
|
在此查询中禁用缓存。
|
2022-08-24 16:23:21 +08:00
|
|
|
|
2023-03-25 12:03:23 +08:00
|
|
|
#### rewrite_ttl
|
|
|
|
|
|
|
|
重写 DNS 回应中的 TTL。
|
|
|
|
|
2024-02-09 18:37:25 +08:00
|
|
|
#### client_subnet
|
|
|
|
|
|
|
|
!!! question "自 sing-box 1.9.0 起"
|
|
|
|
|
|
|
|
默认情况下,将带有指定 IP 地址的 `edns0-subnet` OPT 附加记录附加到每个查询。
|
|
|
|
|
|
|
|
将覆盖 `dns.client_subnet` 与 `servers.[].client_subnet`。
|
|
|
|
|
2024-02-03 17:45:27 +08:00
|
|
|
### 地址筛选字段
|
|
|
|
|
|
|
|
仅对IP地址请求生效。 当查询结果与地址筛选规则项不匹配时,将跳过当前规则。
|
|
|
|
|
|
|
|
!!! note ""
|
|
|
|
|
|
|
|
引用的规则集中的 `ip_cidr` 项也作为地址筛选字段生效。
|
|
|
|
|
|
|
|
#### geoip
|
|
|
|
|
|
|
|
!!! question "自 sing-box 1.9.0 起"
|
|
|
|
|
|
|
|
与查询响应匹配 GeoIP。
|
|
|
|
|
|
|
|
#### ip_cidr
|
|
|
|
|
|
|
|
!!! question "自 sing-box 1.9.0 起"
|
|
|
|
|
|
|
|
与查询相应匹配 IP CIDR。
|
|
|
|
|
|
|
|
#### ip_is_private
|
|
|
|
|
|
|
|
!!! question "自 sing-box 1.9.0 起"
|
|
|
|
|
|
|
|
与查询响应匹配非公开 IP。
|
|
|
|
|
2022-08-24 16:23:21 +08:00
|
|
|
### 逻辑字段
|
|
|
|
|
|
|
|
#### type
|
|
|
|
|
|
|
|
`logical`
|
|
|
|
|
|
|
|
#### mode
|
|
|
|
|
|
|
|
`and` 或 `or`
|
|
|
|
|
|
|
|
#### rules
|
|
|
|
|
2024-02-03 17:45:27 +08:00
|
|
|
包括的规则。
|