Skip to content

Instantly share code, notes, and snippets.

@eyebrowkang
Last active August 15, 2024 02:16
Show Gist options
  • Save eyebrowkang/76b21cd96798f0b83959c203b2287ad1 to your computer and use it in GitHub Desktop.
Save eyebrowkang/76b21cd96798f0b83959c203b2287ad1 to your computer and use it in GitHub Desktop.
my mosdns example config
log:
level: warn
production: true
plugins:
- tag: hosts
type: hosts
args:
files:
- "/etc/mosdns/hosts.txt"
- tag: cache
type: cache
args:
size: 10240
lazy_cache_ttl: 259200
- tag: cn_forward
type: forward
args:
concurrent: 3
upstreams:
- tag: ali_dns
addr: "223.5.5.5"
- tag: dnspod
addr: "119.29.29.29"
- tag: 114_dns
addr: "114.114.114.114"
- tag: proxy_forward
type: forward
args:
concurrent: 3
upstreams:
- tag: cf_doh
addr: "https://1.1.1.1/dns-query"
socks5: "127.0.0.1:7890"
- tag: google_doh
addr: "https://8.8.4.4/dns-query"
socks5: "127.0.0.1:7890"
- tag: cf_dot
addr: "tls://one.one.one.one"
socks5: "127.0.0.1:7890"
- tag: ddns_query
type: sequence
args:
- exec: ttl 30
- exec: $cn_forward
- tag: main
type: sequence
args:
- exec: $hosts
- matches:
- has_resp
exec: accept
- matches:
- qname &/etc/mosdns/reject-list.txt &/etc/mosdns/my-reject-list.txt
exec: reject 3
- matches:
- "qname ddns.my.domain"
exec: goto ddns_query
- exec: $cache
- matches:
- has_resp
exec: accept
- matches:
- qname &/etc/mosdns/direct-list.txt &/etc/mosdns/my-direct-list.txt
exec: $cn_forward
- matches:
- has_resp
exec: accept
- exec: prefer_ipv4
- exec: ecs 1.1.0.1
- exec: $proxy_forward
- tag: udp_server
type: udp_server
args:
entry: main
listen: :53
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# --------------------------------------------------------------
# 项目: CloudflareSpeedTest 自动更新 Hosts
# 版本: 1.0.4
# 作者: XIU2
# 项目: https://github.com/XIU2/CloudflareSpeedTest
# --------------------------------------------------------------
_CHECK() {
while true
do
if [[ ! -e "nowip_hosts.txt" ]]; then
echo -e "该脚本的作用为 CloudflareST 测速后获取最快 IP 并替换 Hosts 中的 Cloudflare CDN IP。\n使用前请先阅读:https://github.com/XIU2/CloudflareSpeedTest/issues/42#issuecomment-768273848"
echo -e "第一次使用,请先将 Hosts 中所有 Cloudflare CDN IP 统一改为一个 IP。"
read -e -p "输入该 Cloudflare CDN IP 并回车(后续不再需要该步骤):" NOWIP
if [[ ! -z "${NOWIP}" ]]; then
echo ${NOWIP} > nowip_hosts.txt
break
else
echo "该 IP 不能是空!"
fi
else
break
fi
done
}
_UPDATE() {
echo -e "开始测速..."
NOWIP=$(head -1 nowip_hosts.txt)
# 这里可以自己添加、修改 CloudflareST 的运行参数
./CloudflareST -o "result_hosts.txt"
[[ ! -e "result_hosts.txt" ]] && echo "CloudflareST 测速结果 IP 数量为 0,跳过下面步骤..." && exit 0
BESTIP=$(sed -n "2,4p" result_hosts.txt | awk -F, '{print $1}' | tr '\n' ' ' | sed 's/ $//')
if [[ -z "${BESTIP}" ]]; then
echo "CloudflareST 测速结果 IP 数量为 0,跳过下面步骤..."
exit 0
fi
echo ${BESTIP} > nowip_hosts.txt
echo -e "\n旧 IP 为 ${NOWIP}\n新 IP 为 ${BESTIP}\n"
# ====这是给黑名单用的====
echo "开始备份 Config 文件..."
\cp -f /etc/mosdns/config.yaml /etc/mosdns/config_backup.yaml
echo -e "开始替换..."
sed -i "s/$NOWIP/$BESTIP/g" /etc/mosdns/config.yaml
# ====白名单用下面的配置====
# echo "开始备份 Hosts 文件..."
# \cp -f /etc/mosdns/hosts.txt /etc/mosdns/hosts_backup.txt
# echo -e "开始替换..."
# sed -i "s/$NOWIP/$BESTIP/g" /etc/mosdns/hosts.txt
echo -e "完成..."
systemctl restart mosdns
}
_CHECK
_UPDATE
log:
level: warn
production: true
api:
http: "0.0.0.0:53535"
plugins:
- tag: hosts
type: hosts
args:
files:
- "/etc/mosdns/hosts.txt"
- tag: cache
type: cache
args:
size: 10240
lazy_cache_ttl: 259200
dump_file: /etc/mosdns/cache.dump
- tag: cn_forward
type: forward
args:
concurrent: 3
upstreams:
- tag: ali_dns
addr: "223.5.5.5"
- tag: dnspod
addr: "119.29.29.29"
- tag: 114_dns
addr: "114.114.114.114"
- tag: proxy_forward
type: forward
args:
concurrent: 3
upstreams:
- tag: cf_doh
addr: "https://1.1.1.1/dns-query"
socks5: "127.0.0.1:7890"
- tag: google_doh
addr: "https://8.8.4.4/dns-query"
socks5: "127.0.0.1:7890"
- tag: cf_dot
addr: "tls://one.one.one.one"
socks5: "127.0.0.1:7890"
- tag: proxy_fallback
type: fallback
args:
primary: proxy_forward
secondary: cn_forward
always_standby: false
- tag: ddns_query
type: sequence
args:
- exec: ttl 30
- exec: $cn_forward
- tag: "cf_ip_set"
type: "ip_set"
args:
files:
- /etc/mosdns/cf-ipv4.txt
- /etc/mosdns/cf-ipv6.txt
- tag: cf_black_hole
type: sequence
args:
- matches:
- qname &/etc/mosdns/cf-black.txt
exec: return
- matches:
- resp_ip $cf_ip_set
exec: black_hole 104.19.5.44 104.19.68.1 104.19.25.61
- tag: main
type: sequence
args:
- exec: $hosts
- matches:
- has_resp
exec: accept
- matches:
- qname &/etc/mosdns/reject-list.txt &/etc/mosdns/my-reject-list.txt
exec: reject 3
- matches:
- "qname ddns.my.domain"
exec: goto ddns_query
- exec: $cache
- exec: jump cf_black_hole
- matches:
- has_resp
exec: accept
- matches:
- qname &/etc/mosdns/direct-list.txt &/etc/mosdns/my-direct-list.txt
exec: $cn_forward
- exec: jump cf_black_hole
- matches:
- has_resp
exec: accept
- exec: prefer_ipv4
- exec: ecs 1.1.0.1
- exec: $proxy_fallback
- exec: jump cf_black_hole
- tag: udp_server
type: udp_server
args:
entry: main
listen: :53
#!/bin/bash
curl --fail -x socks5h://127.0.0.1:7890 -o /etc/mosdns/direct-list.txt https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/china-list.txt && \
curl --fail -x socks5h://127.0.0.1:7890 -o /etc/mosdns/reject-list.txt https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/reject-list.txt && \
curl --fail -x socks5h://127.0.0.1:7890 -o /etc/mosdns/cf-ipv4.txt https://www.cloudflare.com/ips-v4/ && \
curl --fail -x socks5h://127.0.0.1:7890 -o /etc/mosdns/cf-ipv6.txt https://www.cloudflare.com/ips-v6/ && \
systemctl restart mosdns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment