部署

docker 部署

这里我关联了nginx-proxy-manager容器(nginx proxy manager)volumes的相关路径,相当于共享了npm的证书。

version: '3.3'
services:
  adguardhome:
    container_name: adguardhome
    restart: unless-stopped
    volumes:
      - /root/adguard/work:/opt/adguardhome/work
      - /root/adguard/conf:/opt/adguardhome/conf
      # npm容器里对应的https证书路径,DOH会用到,具体路径根据自己证书路径修改
      - /root/npm/letsencrypt/archive/npm-2/:/opt/adguardhome/cert
    ports:
      - 53:53/tcp
      - 53:53/udp # 占用53端口
      - 67:67/udp
      - 68:68/udp
      - 8081:80/tcp
      - 8443:443/tcp
      - 8443:443/udp
      - 3000:3000/tcp
      - 853:853/tcp
      - 853:853/udp
      # - 784:784/udp
      # - 8853:8853/udp
      - 5443:5443/tcp
      - 5443:5443/udp
    image: adguard/adguardhome

DOH配置

内网其实不需要DNS-over-HTTPS,一般都是直接填内网ip。

外网的话,需要配置证书,参考

  1. 打开:设置-加密设置-启用加密
  2. 填写:服务器名称:域名
  3. 填写:https端口:443(和docker-compose里的配置一致)
  4. 填写:证书-设置证书路径:/opt/adguardhome/cert/fullchain1.pem(根据映射路径来填)
  5. 填写:私钥-设置私钥路径:/opt/adguardhome/cert/privkey1.pem(根据映射路径来填)
  6. 保存配置 至此,已经可以通过https://yourhost/dns-query进行doh查询了,测试方法:
执行
dnslookup www.baidu.com https://yourhost.com/dns-query
返回
dnslookup v1.3.0
dnslookup result:
;; opcode: QUERY, status: NOERROR, id: 63271
;; flags: qr rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.baidu.com. IN       A

;; ANSWER SECTION:
www.baidu.com.  20      IN      CNAME   www.a.shifen.com.
www.a.shifen.com.       20      IN      A       183.2.172.42
www.a.shifen.com.       20      IN      A       183.2.172.185

nginx 代理隐藏路径

通过nginx代理,将/dns-query 路径修改为其它随机字符串,防止主动探测,同时也可以将控制面板路径修改为复杂地址,参考

  1. 首先代理adguard:在npm面板中,添加adguard的对应proxy规则。
  2. 添加Custom locations,用于屏蔽并自定义转发/dns-query,需要2条locations。
location /dq {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass https://192.168.100.4:8443/dns-query;
}

上图的配置中,把路径为/dns-query的请求终止(直接返回404),而路径为/dq的请求则被转发到了真正的服务路径https://xxx/dns-query上。

至此,可以通过https://xxx/dq进行doh查询了。

附linux DOH验证脚本

参考

wget https://github.com/ameshkov/dnslookup/releases/download/v1.3.0/dnslookup-linux-amd64-v1.3.0.tar.gz

tar zxf dnslookup-linux-amd64-v1.3.0.tar.gz && cd linux-amd64

# DNS over TLS
./dnslookup www.baidu.com tls://doh.dns.com

# DNS over HTTPS
./dnslookup www.google.com https://doh.dns.com/dns-query

其他

53端口被占用的解决方法

https://blognext.net/adguard-home/ 一般是systemd-resolved占用了,禁用就行(这是ubuntu用于DNS解析的进程)。

sudo systemctl disable systemd-resolved.service
sudo systemctl stop systemd-resolved

过滤广告的规则

一般用AdGuard DNS filter+Halflife就够了。

参考:

名称简介地址
AdGuard DNS FilterAdGuard 官方维护的广告规则,涵盖多种过滤规则https://raw.githubusercontent.com/AdguardTeam/FiltersRegistry/master/filters/filter_15_DnsFilter/filter.txt
EasyListAdblock Plus 官方维护的广告规则https://easylist-downloads.adblockplus.org/easylist.txt
EasyList China面向中文用户的 EasyList 去广告规则https://easylist-downloads.adblockplus.org/easylistchina.txt
EasyPrivacy反隐私跟踪、挖矿规则https://easylist-downloads.adblockplus.org/easyprivacy.txt
Halflife规则涵盖了 EasyList China、EasyList Lite、CJX ’s Annoyance、乘风视频过滤规则,以及补充的其它规则https://raw.githubusercontent.com/o0HalfLife0o/list/master/ad.txt
Xinggsf 乘风过滤国内网站广告过滤规则https://raw.githubusercontent.com/xinggsf/Adblock-Plus-Rule/master/rule.txt
Xinggsf 乘风视频过滤视频网站广告过滤规则https://raw.githubusercontent.com/xinggsf/Adblock-Plus-Rule/master/mv.txt
MalwareDomainList恶意软件过滤规则https://www.malwaredomainlist.com/hostslist/hosts.txt
Adblock Warning Removal List去除禁止广告拦截提示规则https://easylist-downloads.adblockplus.org/antiadblockfilters.txt
Anti-AD命中率高、兼容性强https://anti-ad.net/easylist.txt
Fanboy’s Annoyances List去除页面弹窗广告规则https://easylist-downloads.adblockplus.org/fanboy-annoyance.txt