Skip to content

Instantly share code, notes, and snippets.

@suienzan
Last active March 31, 2024 03:36
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save suienzan/4c42a575a7902e19b2029e2dafb83ace to your computer and use it in GitHub Desktop.
Save suienzan/4c42a575a7902e19b2029e2dafb83ace to your computer and use it in GitHub Desktop.
config.yaml and Pacman hook for https://aur.archlinux.org/packages/mosdns-bin v5
log:
level: info
plugins:
# 缓存mosdns-install.hook
- tag: cache
type: cache
args:
size: 1024
lazy_cache_ttl: 86400
# 转发至本地服务器 DNSPod
- tag: forward_local
type: forward
args:
upstreams:
- addr: https://1.12.12.12/dns-query
# 转发至远程服务器 DNS.SB
- tag: forward_remote
type: forward
args:
upstreams:
- addr: 45.11.45.11
- addr: https://45.11.45.11/dns-query
# fallback 用本地服务器 sequence
# 返回不包含本地 ip 则 reject
- tag: local_ip_sequence
type: sequence
args:
- exec: $forward_local
- matches: resp_ip &/etc/mosdns/CN-ip-cidr.txt
exec: accept
- exec: drop_resp # v5.1.2 以后不能用 reject
# fallback 用远程服务器 sequence
- tag: remote_sequence
type: sequence
args:
- exec: $forward_remote
- exec: accept
# fallback 用远程服务器 sequence
- tag: "fallback"
type: "fallback"
args:
primary: local_ip_sequence
secondary: remote_sequence
threshold: 500
always_standby: true
# 主要的运行逻辑插件
# sequence 插件中调用的插件 tag 必须在 sequence 前定义,
# 否则 sequence 找不到对应插件。
- tag: main_sequence
type: sequence
args:
- matches: qname &/etc/mosdns/reject-list.txt
exec: reject
- exec: $cache
- matches: has_resp
exec: accept
- matches: qname &/etc/mosdns/direct-list.txt
exec: $forward_local
- matches: has_resp
exec: accept
- exec: $fallback
# 启动 udp 服务器。
- tag: udp_server
type: udp_server
args:
entry: main_sequence
listen: 127.0.0.1:53
- tag: udp_server_v6
type: udp_server
args:
entry: main_sequence
listen: "[::1]:53"
# /etc/pacman.d/hooks/mosdns-install.hook
[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
# Target = mosdns # uncomment if needed
Target = mosdns-bin
[Action]
Depends = curl
When = PostTransaction
# geodata from `https://github.com/Loyalsoldier/v2ray-rules-dat` and `https://github.com/Hackl0us/GeoIP2-CN`
# If you cannot access `cdn.jsdelivr.net`, change all `cdn.jsdelivr.net` to `gcore.jsdelivr.net`.
Exec = /usr/bin/bash -c "cd /etc/mosdns && /usr/bin/curl -J --remote-name-all https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/direct-list.txt https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/reject-list.txt https://cdn.jsdelivr.net/gh/Hackl0us/GeoIP2-CN@release/CN-ip-cidr.txt && systemctl restart mosdns"
# /etc/pacman.d/hooks/mosdns-remove.hook
[Trigger]
Operation = Remove
Type = Package
# Target = mosdns # uncomment if needed
Target = mosdns-bin
[Action]
When = PostTransaction
Exec = /usr/bin/bash -c "rm /etc/mosdns/CN-ip-cidr.txt /etc/mosdns/direct-list.txt /etc/mosdns/reject-list.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment