跳转至

可选:SmartDNS 集成

参考运营商DNS有污染,使用SmartDNS来接管国内外域名解析,加入国内DOH服务器获取正确地址,同时使用国外DOH服务器作 Fallback 来抗污染,防止 特定域名 即使没走运营商DNS,走了国内的 DOH服务器 还是被污染解析到127.0.0.1这种本地地址。

Nikki设置

混入配置-DNS设置 参考如下:

dns:
  cache-algorithm: arc
  enable: true
  listen: '[::]:1053'
  ipv6: true
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  fake-ip-range6: fdfe:dcba:9876::1/64
  fake-ip-filter:
    - rule-set:Lan
    - rule-set:OpenClash_Default
    - geosite:private
    - geosite:google-cn
    - geosite:category-games
    - geosite:category-game-platforms-download
    - geosite:category-public-tracker
    - geosite:cn
  fake-ip-filter-mode: blacklist
  use-system-hosts: true
  use-hosts: true
  default-nameserver:
    - 127.0.0.1:6053
  proxy-server-nameserver:
    - 127.0.0.1:6053
  direct-nameserver:
    - 127.0.0.1:6053
  nameserver:
    - 127.0.0.1:6553
  nameserver-policy:
#   "geosite:category-ads-all": rcode://success
#   "rule-set:anti-ad": rcode://success
#   "rule-set:AWAvenue-Ads-Rule": rcode://success
#   "rule-set:AdRules Clash Domainset List": rcode://success
#   这里对应nikki设置里面可选geosite,rule-set广告拦截部分
#   "geosite:nikke":
#     - 127.0.0.1:6553
#   这里对应nikki设置里面可选geosite分流部分
    "geosite:private,google-cn,category-games@cn,category-game-platforms-download,category-public-tracker,cn":
      - 127.0.0.1:6053
    "rule-set:Lan":
      - 127.0.0.1:6053
    "rule-set:OpenClash_Default":
      - 127.0.0.1:6053
profile:
  store-selected: true
  store-fake-ip: true

SmartDNS 设置

SmartDNS 下载地址:

https://github.com/pymumu/smartdns/releases

一般下载 openwrt-allall-luci-all 版本.

参考图里设置,不能设置为 dnsmasq 上游,前面的 DHCP/DNS 里面 重定向DNS到DNSMASQ 也保持关闭,不然 nikki 劫持DNS会失效,同时在 nikki 代理配置-路由器代理 里面添加 service/smartdns 不走 nikki DNS 劫持,只走代理,防止国外DNS服务器直连,我们只需要 nikki 劫持DNS。

在这里添加上游服务器,添加国内的DNS服务器和国外DOH服务器,DNS服务器列表参考如下网址:https://dns.icoa.cn/

国内DNS服务器不需要排除默认组,国外DNS服务器需要 从默认组中排除:

设置DOH服务器后,如果使用上面的 Nikki设置-DNS 的话,务必添加 DOT 或者 udp53 的DNS服务器,防止 default-nameserver 解析不到填入的 DOH服务器

同时在 DHCP/DNS 中,开启 允许本机:

确保 忽略解析文件 保持未勾选:

(可选)国外DOH服务器可以加上 EDNS 达到加快解析的效果,参考:

https://pymumu.github.io/smartdns/config/edns-client-subnet/

还是在 额外的服务器参数 里面加上如下:

-subnet [使用的节点的ip-cidr]

面板查看具体节点的IP

来到https://www.ip138.com/,输入节点的ip查询,然后复制Linux子网掩码填入到 [使用的节点的ip-cidr] 里面就行

在系统 DHCP/DNS 中,关闭DNS缓存,缓存交给SmartDNS来完成

高级设置如下,在 包含配置文件 里面可选去广告规则:

这里可以设置定时更新去广告规则,和 nikki 里面去广告搭配使用效果类似.

相关下载地址:

https://anti-ad.net/anti-ad-for-smartdns.conf

https://adrules.top/smart-dns.conf

Tip

这里更加推荐使用作者的去广告规则 对上游规则(如anti-AD、AWAvenue Ads Rule等)进行了合并、去重、去除无效域名,不做任何修改,更加精确. - 全量规则加速链接 - Lite 规则加速链接

第二DNS服务器开启,里面配置为国外DNS服务器:

最终的 SmartDNS 配置

参考如下:

cat /var/etc/smartdns/smartdns.conf
root@OpenWrt:~# cat /var/etc/smartdns/smartdns.conf
server-name smartdns
prefetch-domain yes
serve-expired yes
cache-size 10000
dnsmasq-lease-file /tmp/dhcp.leases
rr-ttl-min 600
rr-ttl-max 43200
rr-ttl-reply-max 1800
log-size 64K
log-num 1
log-level error
log-file /etc/smartdns/smartdns.log
audit-enable yes
audit-size 64K
audit-num 1
audit-file /etc/smartdns/smartdns-audit.log
cache-persist yes
cache-file /etc/smartdns/smartdns.cache
force-qtype-SOA  65
resolv-file /tmp/resolv.conf.d/resolv.conf.auto
bind [::]:6053
bind-tcp [::]:6053
bind [::]:6553  -group Fallback -force-https-soa
bind-tcp [::]:6553  -group Fallback -force-https-soa
server-tls dns.alidns.com  -group CN 
server-https https://1.1.1.1/dns-query  -tls-host-verify dns.cloudflare.com -host-name dns.cloudflare.com -http-host dns.cloudflare.com -group Fallback -exclude-default-group
server-https https://8.8.8.8/dns-query  -tls-host-verify dns.google -host-name dns.google -http-host dns.google -group Fallback -exclude-default-group
conf-file '/etc/smartdns/conf.d/anti-ad-for-smartdns'
conf-file '/etc/smartdns/conf.d/adrules.top'
domain-set -name domain-forwarding-list -file /etc/smartdns/domain-forwarding.list
domain-rules /domain-set:domain-forwarding-list/  -dualstack-ip-selection yes
domain-set -name domain-block-list -file /etc/smartdns/domain-block.list
domain-rules /domain-set:domain-block-list/ -address #
conf-file /etc/smartdns/address.conf
conf-file /etc/smartdns/blacklist-ip.conf
conf-file /etc/smartdns/custom.conf

启用 WebUI:

1
2
3
4
5
6
7
8
# Add custom settings here.
# please read https://pymumu.github.io/smartdns/config/basic-config/
plugin smartdns_ui.so
smartdns-ui.www-root /usr/share/smartdns/wwwroot
smartdns-ui.ip http://0.0.0.0:6080
data-dir /etc/smartdns/data
# (可选)启用网页WebUI的控制台终端
# smartdns-ui.enable-terminal yes

使用你的 ip:6080 来访问 SmartDNS 的网页管理界面

默认账户:admin

默认密码:password

进入后查看DNS解析情况:

上游服务器查看详细信息: