Skip to content

Commit

Permalink
update doc for new option: group-match and global rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed Jan 10, 2024
1 parent bcd7090 commit a0ff840
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 72 deletions.
104 changes: 54 additions & 50 deletions docs/config/client-rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,44 @@ smartdns支持根据客户端IP地址,对客户端设置不同的规则,可

## 家长控制

设置smartdns针对特定的客户端使用特定的上游查询,也可以设置禁止访问特定的域名或IP地址,来实现家长控制。

```
# 启用规则组
group-begin child
# 设置规则组对应的客户端IP
client-rules 192.168.1.13
# 设置规则组使用的上游服务器
server 1.2.3.4 -e
# 禁止特定域名
address /block.com/#
# 禁止特定IP
ignore-ip 2.2.2.2
group-end
```
设置smartdns针对特定的客户端使用特定的上游查询,也可以设置禁止访问特定的域名或IP地址,来实现家长控制。

```
# 启用规则组
group-begin child
# 设置规则组对应的客户端IP
client-rules 192.168.1.13
# 设置规则组使用的上游服务器
server 1.2.3.4 -e
# 禁止特定域名
address /block.com/#
# 禁止特定IP
ignore-ip 2.2.2.2
group-end
```

为方便管理,也可采用多配置文件的方式,如

1. 主配置文件
```
conf-file child.conf -group child
```
1. 主配置文件

1. 包含的配置文件
```
# 设置规则组对应的客户端IP
client-rules 192.168.1.13
# 设置规则组使用的上游服务器
server 1.2.3.4 -e
# 禁止特定域名
address /block.com/#
# 禁止特定IP
ignore-ip 2.2.2.2
```
```
conf-file child.conf -group child
```

其中group-begin和group-end的配置块,等价于conf-file -group 包含的配置文件,
1. 包含的配置文件

```
# 设置规则组对应的客户端IP
client-rules 192.168.1.13
# 设置规则组使用的上游服务器
server 1.2.3.4 -e
# 禁止特定域名
address /block.com/#
# 禁止特定IP
ignore-ip 2.2.2.2
```

其中group-begin和group-end的配置块,等价于conf-file -group 包含的配置文件,

## 访问控制

Expand All @@ -65,22 +67,24 @@ client-rules 192.168.1.2/24

类似家长控制,smartdns可以将特定需要分流和配合ipset/nftset访问的主机,进行分流。

1. 主配置文件
```
conf-file oversea.conf -group oversea
```

1. 包含的配置文件
```
# 设置规则组对应的客户端IP
client-rules 192.168.1.13
# 设置规则组使用的上游服务器
server-https https://1.2.3.4 -e
server-tls tls://1.2.3.4 -e
# 禁止测速
speed-check-mode none
# 禁止IPV6和HTTPS记录
force-qtype-SOA 28 65
# 设置ipset
ipset oversea
```
1. 主配置文件

```
conf-file oversea.conf -group oversea
```

1. 包含的配置文件

```
# 设置规则组对应的客户端IP
client-rules 192.168.1.13
# 设置规则组使用的上游服务器
server-https https://1.2.3.4 -e
server-tls tls://1.2.3.4 -e
# 禁止测速
speed-check-mode none
# 禁止IPV6和HTTPS记录
force-qtype-SOA 28 65
# 设置ipset
ipset oversea
```
8 changes: 8 additions & 0 deletions docs/config/domain-address.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ address除了可以设置屏蔽广告外,还可以指定域名的IP地址。
* /domain/为后缀匹配算法,范围包含其子域名。
* ip: 可以为IPV6,或IPV4地址,可以指定多个IP地址,如果有多个IP地址,查询的时候,将会进行随机排序。

1. 设置全局屏蔽IPV6

```
address #6
```

当不指定域名时,设置全局规则。

1. 指定IPV6

```shell
Expand Down
40 changes: 37 additions & 3 deletions docs/config/domain-rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,49 @@ hide:

为方便对同一个域名设置多个规则,smartdns提供了`domain-rules`参数,可以对域名设置多个规则。

1. 使用`domain-rules`设置多个规则,如:
## 规则设置

使用`domain-rules`设置多个规则,如:

```
domain-rules /a.com/ -g group -address #6 -ipset ipset
# 设置全局规则。
domain-rules /./ -no-cache
```

domain-rules的选项请阅读配置选项。常用选项:

|参数|功能|
|---|---|
|`-group`|设置对应的规则组|
|`-address`|指定域名地址|
|`-nameserver`|指定上游服务器组|
|`-speed-check-mode`|测速模式|
|`-dualstack-ip-selection`|双栈优选|
|`-no-cache`|停止缓存|
|`-no-ip-alias`|忽略ip集合规则|
|`-ipset [ipsetname]`|将对应请求的结果放入指定ipset|
|`-nftset [nftsetname]`|将对应的请求结果放入指定的nftset|


## 域名通配

/domain/域名匹配规则符号。

```shell
// 通配
*-a.example.com
// 仅匹配子域名
*.example.com
// 仅匹配主域名
-.example.com
```

domain-rules的选项请阅读配置选项。
注意:* 和 - 仅支持写在域名开头。其他位置的写法均不支持。

## 域名集合

1. 在有/domain/配置的选项使用域名集合,只需要将`/domain/`配置为`/domain-set:[集合名称]/`即可,如:
在有/domain/配置的选项使用域名集合,只需要将`/domain/`配置为`/domain-set:[集合名称]/`即可,如:

```shell
domain-set -name ad -file /etc/smartdns/ad-list.conf
Expand Down
50 changes: 50 additions & 0 deletions docs/config/rule-group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
hide:
- toc
---

# 规则组

smartdns支持规则组,不同的规则组之间隔离,方便按照域名或客户端匹配过滤规则。

相关的参数有

| 参数 | 功能 |
|--|--|
| group-begin [-g\|group group-name] | 规则组开始
| group-end | 规则组结束
| group-match | 匹配规则组条件,可以设置域名或客户端IP。
| conf-file -group | 以指定规则组包含文件,等价group-begin, group-end


通过group-match可以指定匹配规则,有客户端IP:`-client-ip cidr`,域名:`-domain`

## 按域名或客户端IP匹配规则组

```
# 规则开始,指定名称为rule。
group-begin rule
# 设置匹配规则,如下为匹配IP或者域名。
group-match -client-ip 192.168.1.1/24 -domain a.com
# 设置相关的规则
address #
# 规则结束
group-end
```

## 包含文件规则组

也可以包含外部文件处理规则组,方便维护管理。

主要文件包含外部文件,并且`-group`指定规则组名称

```
conf-file client.conf -group rule
```

包含的规则文件,指定匹配条件

```
group-match -client-ip 192.168.1.1/24 -domain a.com
address #
```
3 changes: 2 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ hide:
| acl-enable | 启用ACL | no | [yes\|no] <br /> 和client-rules搭配使用。| acl-enable yes |
| group-begin | 规则组开始 || 组名:<br /> 和group-end搭配使用,启用此参数后,group-begin参数之后的配置项将设置到对应的组中,直到group-end结束。| group-begin group-name |
| group-end | 规则组结束 || 和group-begin搭配使用 | group-end |
| group-match | 匹配组规则 | 无 | 当满足条件时使用对应的规则组<br />[-g\|group group-name]: 指定规则组,可选,不指定时,使用当前group-begin的组。<br />[-client-ip ip/cidr]: 指定客户端IP地址,匹配时,使用指定的组。<br />[-domain domain]: 指定域名,匹配时使用指定的组。 | group-match -client-ip 1.1.1.1 -domain a.com
| conf-file | 附加配置文件 || path [-g\|group group-name] <br />path: 合法路径字符串,通配符号 <br />[-g\|group]: 对应配置文件配置所属规则组 | conf-file /etc/smartdns/smartdns.more.conf <br /> conf-file \*.conf <br /> conf-file \*.conf -group oversea |
| server | 上游 UDP DNS || 可重复。<br />[ip][:port]\|URL:服务器 IP:端口(可选)或 URL <br />[-blacklist-ip]:配置 IP 过滤结果。<br />[-whitelist-ip]:指定仅接受参数中配置的 IP 范围<br />[-g\|-group [group] ...]:DNS 服务器所属组,比如 office 和 foreign,和 nameserver 配套使用<br />[-e\|-exclude-default-group]:将 DNS 服务器从默认组中排除。<br />[-set-mark mark]:设置数据包标记so-mark。<br />[-p\|-proxy name]:设置代理服务器。 <br />[-b\|-bootstrap-dns]:标记此服务器为bootstrap服务器。<br />[-subnet]:指定服务器使用的edns-client-subnet。<br />[-interface]:绑定到对应的网口。| server 8.8.8.8:53 -blacklist-ip -group g1 -proxy proxy<br /> server tls://8.8.8.8|
| server-tcp | 上游 TCP DNS || 可重复。<br />[ip][:port]:服务器 IP:端口(可选)<br />[-blacklist-ip]:配置 IP 过滤结果<br />[-whitelist-ip]:指定仅接受参数中配置的 IP 范围。<br />[-g\|-group [group] ...]:DNS 服务器所属组,比如 office 和 foreign,和 nameserver 配套使用<br />[-e\|-exclude-default-group]:将 DNS 服务器从默认组中排除。<br />[-set-mark mark]:设置数据包标记so-mark。<br />[-p\|-proxy name]:设置代理服务器。 <br />[-b\|-bootstrap-dns]:标记此服务器为bootstrap服务器。<br />[-subnet]:指定服务器使用的edns-client-subnet。<br />[-interface]:绑定到对应的网口。| server-tcp 8.8.8.8:53 |
Expand All @@ -58,7 +59,7 @@ hide:
| speed-check-mode | 测速模式选择 | ping,tcp:80,tcp:443 | [ping\|tcp:[80]\|none] | speed-check-mode ping,tcp:80,tcp:443 |
| response-mode | 首次查询响应模式 | first-ping |模式:[first-ping\|fastest-ip\|fastest-response]<br /> [first-ping]: 最快ping响应地址模式,DNS上游最快查询时延+ping时延最短,查询等待与链接体验最佳;<br />[fastest-ip]: 最快IP地址模式,查询到的所有IP地址中ping最短的IP。需等待IP测速; <br />[fastest-response]: 最快响应的DNS结果,DNS查询等待时间最短,返回的IP地址可能不是最快。| response-mode first-ping |
| expand-ptr-from-address | 是否扩展Address对应的PTR记录 | no | [yes\|no] | expand-ptr-from-address yes |
| address | 指定域名 IP 地址 || address /[*\|-.]domain/[ip1[,ip2,...]\|-\|-4\|-6\|#\|#4\|#6] <br />- 表示忽略此规则 <br /># 表示返回 SOA <br />4 表示 IPv4 <br />6 表示 IPv6 <br /> * 开头表示通配<br />- 开头表示主域名<br /> `*``-` 只能在域名开头,其他位置不生效。| address /www.example.com/1.2.3.4<br />address /www.example.com/::1 <br />address /example.com/1.2.3.4,5.6.7.8 <br /> address /\*-a.example.com/ <br /> address /\*.example.com/ <br > address /-.example.com/|
| address | 指定域名 IP 地址 || address [/[*\|-.]domain/][ip1[,ip2,...]\|-\|-4\|-6\|#\|#4\|#6] <br />- 表示忽略此规则 <br /># 表示返回 SOA <br />4 表示 IPv4 <br />6 表示 IPv6 <br /> * 开头表示通配<br />- 开头表示主域名<br /> `*``-` 只能在域名开头,其他位置不生效。<br />不指定域名表示对所有域名生效。| address /www.example.com/1.2.3.4<br />address /www.example.com/::1 <br />address /example.com/1.2.3.4,5.6.7.8 <br /> address /\*-a.example.com/ <br /> address /\*.example.com/ <br > address /-.example.com/ <br /> address #6 <br /> address -6|
| cname | 指定域名别名 || cname /domain/target <br />- 表示忽略此规则 <br />指定对应域名的cname | cname /www.example.com/cdn.example.com |
| srv-record | 指定SRV记录 || srv-record /domain/[target][,port][,priority][,weight] | srv-record /_vlmcs._tcp/example.com,1688,1,1|
| ddns-domain | 指定DDNS域名 | 无 | ddns-domain doamin.com, 用于将指定的域名解析为smartdns所在主机IP地址。| ddns-domain example.com
Expand Down
14 changes: 11 additions & 3 deletions en/docs/config/domain-address.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ In addition to blocking ads, `address` can also be used to specify the IP addres
* `/domain/` uses suffix matching algorithm, including subdomains.
* `ip`: can be an IPv6 or IPv4 address.

1. Set global blocking for IPV6.

```
address #6
```

When no domain is specified, set global rules.

1. Specify IPv6

```shell
Expand All @@ -30,11 +38,11 @@ In addition to blocking ads, `address` can also be used to specify the IP addres
1. The prefix wildcard matches the main domain name

```shell
// prefix wild card
# prefix wild card
*-a.example.com
// only match subdomains
# only match subdomains
*.example.com
// only match the main domain name
# only match the main domain name
-.example.com
```

Expand Down
61 changes: 47 additions & 14 deletions en/docs/config/domain-rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,55 @@ hide:

To facilitate setting multiple rules for the same domain, smartdns provides the `domain-rules` parameter, which allows you to set multiple rules for a domain.

1. Use the `domain-rules` parameter to set multiple rules, for example:
## Rule Settings

```
domain-rules /a.com/ -g group -address #6 -ipset ipset
```
Use `domain-rules` to set multiple rules, for example:

Please refer to the configuration options for more information on the `domain-rules` options.
```
domain-rules /a.com/ -g group -address #6 -ipset ipset
```

1. When using domain sets in options with `/domain/` configuration, you only need to replace `/domain/` with `/domain-set:[set name]/`, for example:
Please refer to the configuration options for more information on the `domain-rules` options.

```shell
domain-set -name ad -file /etc/smartdns/ad-list.conf
domain-rules /domain-set:ad/ -a #
```
| Parameter | Function |
|---|---|
|`-group`|Set the corresponding rule group|
|`-address`|Set domain address|
|`-nameserver`|Set upstream server group|
|`-speed-check-mode`|Set speed check mode|
| `-no-dualstack-selection` | Disable dual-stack speed test |
|`-no-cache`|No cache|
| `-no-cache` | Stop caching |
| `-no-ip-alias` |Ignore IP alias rules|
| `-ipset [ipsetname]` |Put the corresponding request result into the specified ipset|
| `-nftset [nftsetname]` |Put the corresponding request result into the specified nftset|

```shell
domain-set -name ad -file /etc/smartdns/ad-list.conf
domain-rules /domain-set:ad/ -a #
```

## Domain Wildcards

The prefix wildcard matches the main domain name

```shell
# prefix wild card
*-a.example.com
# only match subdomains
*.example.com
# only match the main domain name
-.example.com
```

Note: * and - are only supported at the beginning of the domain name. Wording in other locations is not supported.

## Domain Set

When using domain sets in options with `/domain/` configuration, you only need to replace `/domain/` with `/domain-set:[set name]/`, for example:

```shell
domain-set -name ad -file /etc/smartdns/ad-list.conf
domain-rules /domain-set:ad/ -a #
```

```shell
domain-set -name ad -file /etc/smartdns/ad-list.conf
domain-rules /domain-set:ad/ -a #
```
Loading

0 comments on commit a0ff840

Please sign in to comment.