跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[宽带症候群] AdGuard+MosDNS+OpenClash 套娃代理组合

发表于

重发一遍,完善配置文件,把坑都踩了一遍,教程经验总结

自行安装 3 个插件,luci-app-openclash luci-app-mosdns luci-app-adguardhome

OpenClash 配置:

插件设置 - 模式设置 - 运行模式: 切换到 Fake-IP (增强)模式

插件设置 - DNS 设置 - 本地 DNS 劫持 选择 禁用

插件设置 - 流量控制 - 绕过中国大陆 IP 取消勾选

插件设置 - 流量控制 - 仅允许内网 开启

插件设置 - IPv6 设置 这页的选项全都关闭就行了

覆写设置 - 常规设置 这里都不用改,只需要记住 DNS 监听,后面配置 mosdns 要用

覆写设置 - DNS 设置 - 自定义上游 DNS 服务器 勾选

覆写设置 - DNS 设置 - 追加上游 DNS 勾选

覆写设置 - DNS 设置 - 追加默认 DNS 勾选

覆写设置 - DNS 设置 - Fake-IP 持久化 勾选

覆写设置 - DNS 设置 页面下方 NameServer ,FallBack ,Default-NameServer 里的 DNS 服务器全都取消勾选,我们只用运营商提供的 DNS 服务器就够了,一般运营商 DNS 都是最快的,也是 CDN 最优化的。

插件设置 - GEO 数据库订阅 把 GeoIP Dat 和 GeoSite 这两个库的自动更新打开,都选 Loyalsoldier 的版本,这个是用来给 mosdns 用的。

uXWWk9E.png

插件设置 - 开发者选项,添加防火墙规则

# This script is called by /etc/init.d/openclash
# Add your custom firewall rules here, they will be added after the end of the OpenClash iptables rules

en_mode=$(uci -q get openclash.config.en_mode)
proxy_port=$(uci -q get openclash.config.proxy_port)

if [ "$en_mode" == "fake-ip" ]; then
	LOG_OUT "limit route to only fake ips with proxy port $proxy_port"
	iptables -t nat -D openclash -p tcp -j REDIRECT --to-ports $proxy_port
	sleep 1

	LOG_OUT "update telegram ipset"
	/etc/mosdns/rule/geoip2ipset.sh /etc/openclash/GeoIP.dat telegram
	iptables -t nat -A openclash -m set --match-set telegram dst -p tcp -j REDIRECT --to-ports $proxy_port
	sleep 1

	LOG_OUT "update netflix ipset"
	/etc/mosdns/rule/geoip2ipset.sh /etc/openclash/GeoIP.dat netflix
	iptables -t nat -A openclash -m set --match-set netflix dst -p tcp -j REDIRECT --to-ports $proxy_port
	sleep 1
fi

#  停止 AdguradHome
LOG_OUT "stop adguardhome"
/etc/init.d/AdGuardHome stop
sleep 1

#  开启 AdguradHome
LOG_OUT "start adguardhome"
/etc/init.d/AdGuardHome start
sleep 1

# 停止 Mosdns
LOG_OUT "stop mosdns"
/etc/init.d/mosdns stop
sleep 1

# 开启 Mosdns
LOG_OUT "start mosdns"
/etc/init.d/mosdns start
sleep 1

# 重载 Mosdns
LOG_OUT "reload mosdns"
/etc/init.d/mosdns reload
sleep 1

exit 0

SSH 登录路由器,添加脚本 vi 和 nano 或者 winscp 都行,脚本路径 /etc/mosdns/rule/geoip2ipset.sh

#!/bin/bash

geoipfile="$1"
tag="$2"
tmpdir="/tmp/v2dat"
FW4=$(command -v fw4)

cd $(cd $(dirname $BASH_SOURCE) && pwd)

mkdir -p "$tmpdir"
filename=$(basename -- "$geoipfile")
filename="${filename%.*}"
filename="$tmpdir/${filename}_$tag.txt"

if [ "$tag" == "telegram" ]; then
    wget -4 --timeout 5 -O "$filename" 'https://mirror.ghproxy.com/https://raw.githubusercontent.com/fernvenue/telegram-cidr-list/master/CIDR.txt'
    if [ "$?" != "0" ]; then
         /usr/bin/v2dat unpack geoip -o "$tmpdir" -f "$tag" "$geoipfile"
    fi
else
    /usr/bin/v2dat unpack geoip -o "$tmpdir" -f "$tag" "$geoipfile"
fi

if test -f "$filename"; then
    if [ -n "$FW4" ]; then
        nft add set inet fw4 "$tag" { type ipv4_addr\; flags interval\;  auto-merge\; }
        nft add set inet fw4 "${tag}6" { type ipv6_addr\; flags interval\;  auto-merge\; }
        nft flush set inet fw4 "$tag"
        nft flush set inet fw4 "${tag}6"
    fi
    ipset create "$tag" hash:net -!
    ipset create "${tag}6" hash:net family inet6 -!
    ipset flush "$tag"
    ipset flush "${tag}6"
    while read p; do
        if ! grep -q ":" <<< "$p"; then
            if [ -n "$FW4" ]; then
                nft add element inet fw4 "$tag" { "$p" }
            fi
            ipset add "$tag" "$p"
        else
            if [ -n "$FW4" ]; then
                nft add element inet fw4 "${tag}6" { "$p" }
            fi
            ipset add "${tag}6" "$p"
        fi
    done <"$filename"
else
    echo "$filename missing."
fi

rm -rf "$tmpdir"

添加脚本执行权限

chmod a+x /etc/mosdns/rule/geoip2ipset.sh

MosDNS 配置:

MosDNS - 配置文件 - 自定义

DNS 转发 - 取消勾选

GeoData 数据导出 添加标签:

GeoSite: cn apple-cn category-games@cn geolocation-!cn GeoIP: cn q8Zvtec.png

自定义配置文件:

log:
  level: info
  file: "/tmp/mosdns.log"

plugins:
  # 缓存插件
  - tag: cache
    type: cache
    args:
      size: 20480
      lazy_cache_ttl: 86400
      
  # 国内域名
  - tag: geosite_cn
    type: domain_set
    args:
      exps:
        - "lan"
        - "local"
        - "arpa"
      files:
        - "/etc/mosdns/rule/whitelist.txt"
        - "/var/mosdns/geosite_cn.txt"
        - "/var/mosdns/geosite_apple-cn.txt"
        - "/var/mosdns/geosite_category-games@cn.txt"

  # 国内 IP
  - tag: geoip_cn
    type: ip_set
    args:
      files:
        - "/var/mosdns/geoip_cn.txt"
        
  # 国外域名
  - tag: geosite_no_cn
    type: domain_set
    args:
      files:
        - "/etc/mosdns/rule/greylist.txt"
        - "/var/mosdns/geosite_geolocation-!cn.txt"
        
  # 国内 DNS
  - tag: forward_local
    type: forward
    args:
      upstreams:
        - addr: "quic://223.5.5.5"      
        - addr: "tls://1.12.12.12"
          enable_pipeline: true      
        - addr: "tls://120.53.53.53"
          enable_pipeline: true
   
  # 国外 DNS
  # 自己查找低延迟 DNS
  - tag: forward_remote
    type: forward
    args:
      upstreams:
        # 101DNS
        - addr: "tls://101.101.101.101"
          enable_pipeline: true
        # NextDNS HK 节点
        - addr: "https://45.11.104.186"
          insecure_skip_verify: true
        # OpenDNS SANDNOX
        - addr: "tls://208.67.222.2"
          enable_pipeline: true
        # OpenDNS 
        - addr: "tls://208.67.222.222"
          enable_pipeline: true                    

  # 私人分流 dns         
  - tag: forward_private
    type: forward
    args:
      upstreams: 
        - addr: "https://doh.apad.pro/dns-query"
          bootstrap: "223.5.5.5" 

          
  # 国内解析
  - tag: local_sequence
    type: sequence
    args:
      - exec: $forward_local
        
  # 国外解析
  - tag: remote_sequence
    type: sequence
    args:
      - exec: prefer_ipv4
      - exec: $forward_remote
      
  # 分流解析    
  - tag: private_sequence
    type: sequence
    args:
      - exec: $forward_private
      
  # clash 解析
  - tag: clash_sequence
    type: sequence
    args:
      - exec: forward 127.0.0.1:7874
      - exec: ttl 0

  # 有响应终止返回
  - tag: has_resp_sequence
    type: sequence
    args:
      - matches: has_resp
        exec: accept

  # fallback 用分流 sequence
  # 返回国外 IP 则用 clash 解析得出 fakeip
  - tag: fallback_sequence
    type: sequence
    args:
      - exec: $private_sequence
      - matches: "!resp_ip $geoip_cn"
        exec: goto clash_sequence
      - exec: accept
      
  # 国外 sequence
  - tag: fallback2_sequence
    type: sequence
    args:
      - exec: $remote_sequence
      - matches: "resp_ip $geoip_cn"
        exec: goto local_sequence
      - exec: goto clash_sequence      

  # fallback 用分流 DNS ,超时后用国外 DNS 解析    
  - tag: fallback
    type: fallback
    args:
      primary: fallback_sequence
      secondary: fallback2_sequence
      threshold: 2000
      always_standby: true

  # 主要的运行逻辑插件
  # sequence 插件中调用的插件 tag 必须在 sequence 前定义,
  # 否则 sequence 找不到对应插件。
  - tag: main_sequence
    type: sequence
    args:
      # drop https query type
      - matches:
        - qtype 65
        exec: reject 3

      # handle local ptr
      - matches:
        - qtype 12
        exec: $local_sequence
      - exec: jump has_resp_sequence

      #FakeIP 不缓存
      - matches:
        - qname $geosite_no_cn
        exec: $clash_sequence
      - exec: jump has_resp_sequence
      
      # 缓存
      - exec: $cache
      - exec: jump has_resp_sequence

      - matches:
        - qname $geosite_cn
        exec: $local_sequence
      - exec: jump has_resp_sequence

      - exec: $fallback

  - tag: udp_server
    type: udp_server
    args:
      entry: main_sequence
      listen: ":5335" #mosdns 监听端口

网络 - 防火墙 - 自定义规则,添加规则,重启防火墙

#5333 是 AdGuardHome 的 DNS 监听端口,两个端口必须一致
iptables -t nat -A PREROUTING -d 198.18.0.0/16 -p tcp -j REDIRECT --to-ports 7892
iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5333
iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5333
ip6tables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 5333
ip6tables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 5333

WRCZolM.png

AdGuardHome 配置:

AdGuardHome - 6060 重定向 - 重定向 53 端口到 AdGuardHome 如果使用上面的 iptables 防火墙规则就忽略这步

更新并且启动 AdGuardHome ,在 Web 管理页面上,设置 - DNS 设置中,上游 DNS 服务器内只填写一个 mosdns 的地址 127.0.0.1:5335 ,私人反向 DNS 服务器写上 127.0.0.1 。DNS 缓存配置里面,缓存大小看你内存大小填写,乐观缓存勾上。

对于不想走代理的设备,可以在设置 - 客户端设置中添加,并且把上游 DNS 服务器设置成 127.0.0.1

查询日志文件 /usr/bin/AdGuardHome/data/querylog.json 会把路由器闪存写满 解决方法:ADG - 常规设置 - 日志配置,取消勾选启用日志,或者将查询日志保留时间改为 6 小时,记得保存

解决谷歌 Play 商店不能更新:

ADG - 过滤器 - 添加 DNS 重写,services.googleapis.cn 198.18.1.50

如果无法使用游戏加速器:OpenClash - 插件设置 - 模式设置,取消勾选 UDP 流量转发

参考教程: https://blog.openwrtcn.eu.org/dnsling-wu-ran/ https://github.com/IrineSistiana/mosdns/discussions/796

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.