add ip-set, ip-rules, ip-alias pages

This commit is contained in:
Nick Peng
2023-10-31 22:21:02 +08:00
parent ef1040c378
commit 4d69057696
10 changed files with 275 additions and 5 deletions

100
docs/config/ip-alias.md Normal file
View File

@@ -0,0 +1,100 @@
---
hide:
- toc
---
# IP别名
smartdns提供了IP地址别名映射功能可以将查询结果中的IP或IP段映射为特定IP地址
此特性可用用于具有anycast IP的CDN网络加速。比如Cloudflare的CDN加速。
## IP别名映射
映射指定的IP地址到目标地址如将1.2.3.4的C类地址全部映射到192.168.1.1
```
ip-alias 1.2.3.4/24 192.168.1.1
```
## 设置特定域名忽略IP别名
某些情况下需要设置特定域名的结果不进行IP别名转换则可通过域名规则忽略IP别名。
```
domain-rules /example.com/ -no-ip-alias
```
## Cloudflare CDN加速
Cloudflare CDN的IP地址都是anycast IP地址用户可通过任意Cloudflare的IP地址来访问其托管的网站。
通过此特性我们可以找到自己网络访问Cloudflare CDN最快的IP地址并设置IP别名来加速所有托管在Cloudflare上的网站。
其步骤如下:
### 获取Cloudflare的IP地址范围并保持为IP列表文件
Cloudflare公开了其CDN的IP地址范围具体范围在这里可以找到https://www.cloudflare.com/ips/
IPV4https://www.cloudflare.com/ips-v4/#
IPV6https://www.cloudflare.com/ips-v6/#
将上述列表保存为文本,比如:`cloudflare-ipv4.txt`, `cloudflare-ipv6.txt`
* cloudflare-ipv4.txt
```
173.245.48.0/20
103.21.244.0/22
103.22.200.0/22
103.31.4.0/22
141.101.64.0/18
108.162.192.0/18
190.93.240.0/20
188.114.96.0/20
197.234.240.0/22
198.41.128.0/17
162.158.0.0/15
104.16.0.0/13
104.24.0.0/14
172.64.0.0/13
131.0.72.0/22
```
* cloudflare-ipv6.txt
```
2400:cb00::/32
2606:4700::/32
2803:f800::/32
2405:b500::/32
2405:8100::/32
2a06:98c0::/29
2c0f:f248::/32
```
### 查找本网络访问Cloudflare最快的IP
社区提供了找到最快Cloudflare IP地址的工具[CloudflareSpeedTest](https://github.com/XIU2/CloudflareSpeedTest)我们可以使用此工具找到最快的IP地址。
对应命令如下
```
./CloudflareSpeedTest -url https://down.heleguo.top/download/100MB.zip
```
执行成功后将会获得最快的IP地址。
由于工具随机使用了一些IP地址测速可以多执行几次上述命令以确保获取到最快IP地址。
### 配置smartdns加速
原理是通过ip-alias命令将Cloudflare的整个anycast IP映射到CloudflareSpeedTest获取到的最快的IP地址上。
配置smartdns如下
```
# 设置Cloudflare IPV4别名映射
ip-set -name cloudflare-ipv4 -file /path/to/cloudflare-ipv4.txt
ip-rules ip-set:cloudflare-ipv4 -ip-alias 162.159.58.17,162.159.58.124
# 设置Cloudflare IPV6别名映射
ip-set -name cloudflare-ipv6 -file /path/to/cloudflare-ipv6.txt
ip-rules ip-set:cloudflare-ipv6 -ip-alias 2606:4700:17:d8e7:5e98:7d62:6674:c5a7
```

View File

@@ -9,10 +9,11 @@ smartdns提供了IP地址黑白名单和忽略相关的结果。
|参数|功能|使用场景|
|---|---|---|
|whitelist-ip|白名单 IP 地址|接受在指定范围内的IP地址设置
|blacklist-ip|黑名单 IP 地址|接受在指定范围外的IP地址设置
|whitelist-ip|白名单 IP 地址|接受在指定范围内的IP地址设置
|blacklist-ip|黑名单 IP 地址|接受在指定范围外的IP地址设置
|ignore-ip|忽略 IP 地址|不需要某个IP地址或IP地址段时设置。
|bogus-nxdomain|假冒 IP 地址过滤|请求结果包含对应IP地址时返回SOA
|bogus-nxdomain|假冒 IP 地址过滤|请求结果包含对应IP地址时返回SOA
|ip-alias|IP别名规则|IP地址映射可用于具备Anycast IP的CDN加速比如Cloudflare的CDN。参考[IP别名](../config/ip-alias.md)。
## 白名单IP地址

29
docs/config/ip-set.md Normal file
View File

@@ -0,0 +1,29 @@
---
hide:
- toc
---
# IP地址集合的使用
为方便按集合配置IP地址对于使用到`ip/subnet`的配置可以指定IP地址集合方便维护。具体方法为
1. 使用`ip-set`配置集合文件,如
```shell
ip-set -name cloudflare -file /etc/smartdns/cloudflare-list.conf
```
cloudflare-list.conf的格式为一个IP地址一行
```shell
1.2.3.4
192.168.1.1/24
```
1. 在有`ip/subnet`配置的选项使用IP地址集合只需要将`ip/subnet`配置为`ip-set:[集合名称]/`即可,如:
```shell
ignore-ip ip-set:cloudflare
ip-rules ip-set:cloudflare -whitelist-ip
ip-alias ip-set:cloudflare 192.168.1.1
```