Files
smartdns/docs/config/ad-block.md
2023-06-03 17:46:49 +08:00

102 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
hide:
- toc
---
# 广告屏蔽
smartdns可以通过address选项来屏蔽广告。
注意openwrt有luci的方式请参考openwrt屏蔽域名配置方法。
## 基本配置方法
1. 通过`address /domain/#`选项屏蔽广告,如。
```shell
address /example.com/#
```
address选项中:
* /domain/为后缀匹配算法,范围包含其子域名。
* 单独`#`表示同时屏蔽IPV4, IPV6
* 使用`#6`表示屏蔽IPV6
* 使用`#4`表示屏蔽IPV4。
* 使用`-`表示不屏蔽此域名。
1. 如单独屏蔽IPV6
```shell
address /example.com/#6
```
1. 如果想不屏蔽某个子域名
```shell
address /sub.example.com/-
```
## 使用域名集合
对于单个域名屏蔽可以方便使用address参数屏蔽对于较多的域名可通过域名集合屏蔽更加方便管理广告域名列表。
```shell
domain-set -name ad -file /path/to/adblock.list
address /domain-set:ad/#
```
adlobck.list的内容为每行一个域名。
```shell
a.com
b.com
...
```
## 使用社区已有smartdns广告过滤列表
社区针对smartdns提供了每日更新的广告列表文件可以直接使用这些广告列表文件smartdns可以通过conf-file选项包含广告屏蔽文件。另外在使用这些广告列表文件时可以定期下载更新文件并重启smartdns生效。
1. 下载配置文件到`/etc/smartdns`目录
```shell
wget https://anti-ad.net/anti-ad-for-smartdns.conf -O /etc/smartdns/anti-ad-smartdns.conf
```
1. 修改/etc/smartdns/smartdns.conf文件包含上述配置文件
```shell
conf-file /etc/smartdns/anti-ad-smartdns.conf
```
## 广告列表
|项目|说明|配置文件|
|--|--|--|
|[anti-AD](https://anti-ad.net/)|Anti Advertising for smartdns|https://anti-ad.net/anti-ad-for-smartdns.conf|
|[adrules](https://adrules.top/)|AdRules SmartDNS List|https://adrules.top/smart-dns.conf |
|[neodevhost](https://github.com/neodevpro/neodevhost/)|AdRules SmartDNS List|https://raw.githubusercontent.com/neodevpro/neodevhost/master/lite_smartdns.conf |
## 非smartdns列表
对于非smartdns的数据可以通过简单的shell命令进行转换。
### hosts格式
如下面命令,可以将`/path/to/hosts/file`的文件路径换成实际的文件转换为smartdns支持的格式
```shell
cat /path/to/hosts/file | grep -v "^#" | awk '{print "address /"$2"/#"}' > anti-ad-smartdns.conf
```
### dnsmasq格式
dnsmasq格式和smartdns类似但不兼容可以通过如下命令转换
```shell
cat /path/to/dnsmasq/file | grep address | awk -F= '{print "address "$2"#"}' > anti-ad-smartdns.conf
```