GitHub - snltty/linker: 极具特色的,P2P打洞(UDP+TCP、IPV4+IPV6) + 服务器转发,实现的异地组网、内网穿透。让你那些散落在世界各地的联网设备就像在隔壁房间一样轻松访问。
极具特色的,P2P打洞(UDP+TCP、IPV4+IPV6) + 服务器转发,实现的异地组网、内网穿透。让你那些散落在世界各地的联网设备就像在隔壁房间一样轻松访问。 - snltty/linker
GitHub (github.com)
UDP P2P
极具特色的,P2P打洞(UDP+TCP、IPV4+IPV6) + 服务器转发,实现的异地组网、内网穿透。让你那些散落在世界各地的联网设备就像在隔壁房间一样轻松访问。 - snltty/linker
GitHub (github.com)
UDP P2P
bluetooth mesh chat, IRC vibes. Contribute to permissionlesstech/bitchat development by creating an account on GitHub.
GitHub (github.com)
蓝牙 去中心化 mesh 通讯
[color=#FF4D4D]环境:Debian 13 Nginx1.31.1[/color]
nano auto_zstd_nginx.sh
#!/usr/bin/env bash
# ==============================================================================
# 脚本名称: auto_zstd_nginx.sh
# 适用系统: Debian 12/13 / Ubuntu
# 功能描述: 具备智能缓存检测的全功能 Nginx Zstd 动态模块编译与全自动更新脚本
# ==============================================================================
set -e # 遇到致命错误立即停止执行
# 颜色输出定义
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
log_info() { echo -e "${GREEN}[INFO] $1${NC}"; }
log_warn() { echo -e "${YELLOW}[WARN] $1${NC}"; }
log_err() { echo -e "${RED}[ERROR] $1${NC}"; exit 1; }
SRC_DIR="/usr/src"
CACHE_META="${SRC_DIR}/.nginx_zstd_cache.meta"
MODULES_INSTALL_DIR="/usr/lib/nginx/modules"
# 1. 权限检查
if [ "$EUID" -ne 0 ]; then
log_err "请使用 root 用户或通过 sudo 运行此脚本!"
fi
# 2. 检测当前运行的 Nginx 状态
if ! command -v nginx &> /dev/null; then
log_err "未检测到系统安装了 Nginx,请先安装 Nginx 主程序!"
fi
# 动态提取当前 Nginx 版本号 (例如: 1.31.0)
NGINX_VER=$(nginx -v 2>&1 | awk -F/ '{print $2}' | cut -d' ' -f1)
NGINX_ARGS=$(nginx -V 2>&1 | grep "configure arguments:" | sed 's/configure arguments://')
log_info "当前系统运行的 Nginx 版本: ${NGINX_VER}"
# 自动修正模块安装路径
if [ ! -d "$MODULES_INSTALL_DIR" ]; then
MODULES_INSTALL_DIR="/etc/nginx/modules"
fi
# 3. 智能检测远端 Zstd 库的最新版本(无需提前克隆)
log_info "正在检测 Facebook Zstd 官方仓库最新动态..."
if ! command -v git &> /dev/null; then
# 如果没有 git,临时安装以便检测
apt-get update -y || true
apt-get install -y git wget awk
fi
# 获取远程最新 Commit ID
REMOTE_ZSTD_COMMIT=$(git ls-remote https://github.com/facebook/zstd.git HEAD | awk '{print $1}')
if [ -z "$REMOTE_ZSTD_COMMIT" ]; then
log_err "无法连接到 GitHub 获取 Zstd 版本,请检查网络连接。"
fi
# 4. 缓存验证:比对版本与文件完整性
NEED_BUILD_ZSTD=true
NEED_BUILD_MODULE=true
if [ -f "$CACHE_META" ]; then
# 读取缓存的元数据
# shellcheck disable=SC1090
source "$CACHE_META"
# 检查本地动态库文件是否存在
if [ -f "/usr/local/lib/libzstd.so" ] && [ "$LAST_ZSTD_COMMIT" == "$REMOTE_ZSTD_COMMIT" ]; then
NEED_BUILD_ZSTD=false
log_info "✨ 检测到本地 Zstd 核心库已是最新版本 (${REMOTE_ZSTD_COMMIT:0:7}),跳过拉取与编译。"
fi
# 检查 Nginx 动态模块文件是否存在并比对版本
if [ -f "${MODULES_INSTALL_DIR}/ngx_http_zstd_filter_module.so" ] && \
[ -f "${MODULES_INSTALL_DIR}/ngx_http_zstd_static_module.so" ] && \
[ "$LAST_NGINX_VER" == "$NGINX_VER" ] && \
[ "$NEED_BUILD_ZSTD" == "false" ]; then
NEED_BUILD_MODULE=false
fi
fi
# 如果一切都未改变,直接退出
if [ "$NEED_BUILD_ZSTD" == "false" ] && [ "$NEED_BUILD_MODULE" == "false" ]; then
log_info "🚀 [完美缓存] 当前 Nginx 编译环境与 Zstd 模块均无任何更新,无需重复编译!"
exit 0
fi
# 5. 解决 APT 签名错误并安装依赖
log_info "正在准备同步系统依赖包..."
# 核心容错:使用 || true 允许非关键性源(如 MySQL 签名过期)报错,不中断脚本
apt-get update -y || log_warn "部分第三方软件源同步失败(例如系统的 MySQL 密钥未找到),脚本将忽略并尝试继续..."
log_info "正在安装与更新必要的编译工具链..."
apt-get install -y build-essential git libpcre3-dev zlib1g-dev libssl-dev debhelper wget
# 如果系统残留了旧的发行版自带库,予以清除以防冲突
if dpkg -l | grep -q libzstd-dev; then
log_warn "清理系统自带的旧版 libzstd-dev 以防链路冲突..."
apt-get remove -y libzstd-dev libzstd1 || true
fi
# 6. 【按需编译】最新的 Zstd 核心库
cd ${SRC_DIR}
if [ "$NEED_BUILD_ZSTD" == "true" ]; then
log_info "正在下载/更新 Zstd 官方源码并进行编译..."
if [ ! -d "zstd" ]; then
git clone --depth 1 https://github.com/facebook/zstd.git
fi
cd zstd
git fetch --depth 1 origin
git reset --hard origin/dev || git reset --hard origin/master # 适配官方默认主分支
log_info "开始编译 Zstd 核心库..."
make -j$(nproc)
make install
ldconfig
log_info "Zstd 核心库编译并安装成功。"
fi
# 7. 【按需编译】Nginx Zstd 动态模块
cd ${SRC_DIR}
if [ "$NEED_BUILD_MODULE" == "true" ]; then
log_info "正在同步 Nginx 源码与动态模块源码..."
# 清理旧的 Nginx 源码目录确保干净编译
rm -rf "nginx-${NGINX_VER}" "nginx-${NGINX_VER}.tar.gz"
wget -c "http://nginx.org/download/nginx-${NGINX_VER}.tar.gz"
tar -zxf "nginx-${NGINX_VER}.tar.gz"
if [ ! -d "zstd-nginx-module" ]; then
git clone https://github.com/tokers/zstd-nginx-module.git
fi
cd zstd-nginx-module && git pull && cd ..
log_info "配置 Nginx 模块环境,无缝继承原生 Nginx 编译参数..."
cd "nginx-${NGINX_VER}"
# 注入原生参数与定制的 Zstd include 路径
eval "./configure ${NGINX_ARGS} --add-dynamic-module=${SRC_DIR}/zstd-nginx-module --with-cc-opt='-I/usr/local/include' --with-ld-opt='-L/usr/local/lib -Wl,-rpath,/usr/local/lib'"
log_info "并行编译 Nginx Zstd 动态模块..."
make modules
log_info "将编译产物自动替换至 Nginx 目录..."
mkdir -p ${MODULES_INSTALL_DIR}
cp objs/ngx_http_zstd_filter_module.so ${MODULES_INSTALL_DIR}/
cp objs/ngx_http_zstd_static_module.so ${MODULES_INSTALL_DIR}/
chmod 644 ${MODULES_INSTALL_DIR}/ngx_http_zstd_*.so
# 检查模块语法
if nginx -t &>/dev/null; then
log_info "Nginx 配置文件语法检查通过,正在平滑重启服务..."
systemctl reload nginx || log_warn "Nginx 重载失败,请手动检查系统服务状态。"
else
log_warn "检测到 Nginx 配置当前存在异常,未自动重载,请执行 'nginx -t' 排查。"
fi
fi
# 8. 写入/更新本地编译缓存元数据
cat > "$CACHE_META" <<EOF
LAST_NGINX_VER="${NGINX_VER}"
LAST_ZSTD_COMMIT="${REMOTE_ZSTD_COMMIT}"
EOF
log_info "=================================================="
log_info "🎉 全功能自动 Nginx Zstd 模块部署/更新任务成功完成!"
log_info "当前缓存状态:Nginx [${NGINX_VER}] | Zstd [${REMOTE_ZSTD_COMMIT:0:7}]"
log_info "=================================================="
chmod +x auto_zstd_nginx.sh
# 执行两次测试版本缓存
sudo ./auto_zstd_nginx.sh
Makes your AI agent think like the laziest senior dev in the room. The best code is the code you never wrote. - DietrichGebert/ponytail
GitHub (github.com)
以下是 MosDNS-X + EasyMosdns 组合的详细安装教程。教程将严格遵循您指定的目录结构和文件处理方式,所有文件将下载至 /etc/mosdns,二进制文件复制到 /usr/local/bin/,并包含权限设置、服务管理及用户自定义修改的方法。
在开始之前,请确保满足以下条件:
root 或具有 sudo 权限的用户。53 端口未被其他 DNS 服务(如 systemd-resolved)占用,并已安装 unzip、wget、curl 等工具:# 更新包索引并安装必要工具(以 Debian/Ubuntu 为例)
sudo apt update && sudo apt install -y wget unzip curl iptables
/etc/mosdns 目录。我们将所有文件集中下载并解压到 /etc/mosdns 目录中。请依次执行以下命令:
创建并进入工作目录
sudo mkdir -p /etc/mosdns
cd /etc/mosdns
下载 EasyMosdns 配置文件压缩包 (v3.5-2)
源地址
# 此处使用最新提供的 v3.5-2 版本配置,如链接失效请访问 GitHub Releases 页面查找最新版本
sudo wget https://github.com/pmkol/easymosdns/archive/refs/tags/v3.5-2.zip -O easymosdns.zip
下载 MosDNS-X 二进制文件压缩包 (v26.05.25)
源地址
# 下载适用于 Linux amd64 架构的二进制文件,如需其他架构请前往 Releases 页面选择对应版本
sudo wget https://github.com/pmkol/mosdns-x/releases/download/v26.05.25/mosdns-linux-amd64.zip -O mosdns-x.zip
此时,/etc/mosdns 目录下应包含两个文件:easymosdns.zip 与 mosdns-x.zip,文件名是重命名的效果。
cd /etc/mosdns
# 1. 解压 EasyMosdns 配置文件(注意:此压缩包内含有顶级目录 easymosdns-3.5-2,我们需要其内部所有内容)
sudo unzip -q easymosdns.zip
sudo mv easymosdns-3.5-2/* . # 将配置内容移至 /etc/mosdns 根目录
sudo rm -rf easymosdns-3.5-2 easymosdns.zip # 清理解压残留与原始压缩包
# 2. 解压 MosDNS-X 二进制文件,仅提取内部的 mosdns 可执行文件
sudo unzip -q mosdns-x.zip mosdns
sudo cp mosdns /usr/local/bin/ # 将二进制文件移入系统 PATH 路径
sudo chmod +x /usr/local/bin/mosdns # 赋予可执行权限
sudo rm -f mosdns-x.zip # 删除已使用完毕的压缩包
EasyMosdns 提供了一套完整的示例配置文件 config.yaml,我们需要基于此文件进行首次启动前的微调。
cd /etc/mosdns
# 1. 检查是否存在 config.yaml 文件
ls -l config.yaml
# 2. (可选)如存在旧配置文件,先创建备份
sudo cp config.yaml config.yaml.bak
MosDNS-X 内置了便捷的服务管理命令(install、start、stop、restart、uninstall)。我们使用以下命令将 MosDNS 安装为系统服务,并立即启动。
# 1. 将 MosDNS 安装为系统服务,指定工作目录为 /etc/mosdns,并使用 config.yaml 作为主配置文件
sudo mosdns service install -d /etc/mosdns -c config.yaml
# 2. 启动服务
sudo mosdns service start
# 3. 查看服务状态(确认是否正常运行)
sudo mosdns service status
# 4. 重启服务
sudo mosdns service restart
# 5. 停止服务
sudo mosdns service stop
服务启动后,可通过以下方式测试 DNS 解析是否正常:
# 使用 dig 或 nslookup 测试本地 DNS(需提前安装 dnsutils 或 bind-utils)
dig @127.0.0.1 google.com
dig @127.0.0.1 qq.com
#或使用nslookip 查看是否默认使用mosdns查询
nslookup qq.com
nslookup qq.com 127.0.0.1
如果返回正确的解析结果,说明服务已正常运行。
# 日志文件优化
crontab -e
# 在文件末尾添加以下内容
0 5 * * * sudo truncate -s 0 /etc/mosdns/mosdns.log && /etc/mosdns/rules/update
EasyMosdns 提供了高度可定制的配置文件,所有配置均位于 /etc/mosdns/config.yaml。用户可根据注释说明进行个性化修改,例如:
protocol: udp 和 protocol: tcp 下方的 addr: 字段,默认端口为 53,可按需更改。upstream 或 remote 相关段落,替换为符合需求的上游地址(如 HTTPS、DoT 等)。修改配置后,需手动重启。若需强制重启,可使用以下命令:
sudo mosdns service restart
| 操作 | 命令 |
|---|---|
| 停止服务 | sudo mosdns service stop |
| 重启服务 | sudo mosdns service restart |
| 查看日志 | sudo journalctl -u mosdns -f |
| 卸载服务 | sudo mosdns service uninstall (将删除服务但保留配置文件) |
| 重置配置 | sudo /etc/mosdns/tools/config-reset (恢复至初始默认配置) |
为方便批量部署,您可将以下代码保存为 install_mosdns.sh,一键完成上述所有操作:
#!/bin/bash
set -e
echo ">>> 开始安装 MosDNS-X + EasyMosdns ..."
# 安装依赖
echo ">>> 安装依赖工具..."
sudo apt update && sudo apt install -y wget unzip curl
# 创建工作目录并进入
sudo mkdir -p /etc/mosdns
cd /etc/mosdns
# 下载文件
echo ">>> 下载 EasyMosdns 配置包..."
sudo wget https://github.com/pmkol/easymosdns/archive/refs/tags/v3.5-2.zip -O easymosdns.zip
echo ">>> 下载 MosDNS-X 二进制包..."
sudo wget https://github.com/pmkol/mosdns-x/releases/download/v26.05.25/mosdns-linux-amd64.zip -O mosdns-x.zip
# 解压与部署
echo ">>> 解压并部署文件..."
sudo unzip -q easymosdns.zip
sudo mv easymosdns-3.5-2/* ./
sudo rm -rf easymosdns-3.5-2 easymosdns.zip
sudo unzip -q mosdns-x.zip mosdns
sudo cp mosdns /usr/local/bin/
sudo chmod +x /usr/local/bin/mosdns
sudo rm -f mosdns-x.zip
# 安装并启动服务
echo ">>> 安装系统服务..."
sudo mosdns service install -d /etc/mosdns -c config.yaml
sudo mosdns service start
echo ">>> 安装完成!"
echo ">>> 服务状态:"
sudo mosdns service status
赋予执行权限并运行:
chmod +x install_mosdns.sh
sudo ./install_mosdns.sh
config.yaml# =============================================
# EasyMosdns v3.5 - 节点IP自动分流版
# 项目地址:https://apad.pro/easymosdns
# 本配置文件用于 MosDNS-X 或原版 MosDNS
# Github:
# 配置https://github.com/pmkol/easymosdns
# 二进制:https://github.com/pmkol/mosdns-x/
# =============================================
# ---------------------------------------------
# 日志配置
# ---------------------------------------------
log:
file: "./mosdns.log" # 日志文件存放路径
level: info # 日志级别:debug/info/warn/error
# ---------------------------------------------
# 数据源配置(规则文件)
# 所有规则文件位于 ./rules/ 目录下
# ---------------------------------------------
data_providers:
- tag: chinalist # 中国域名列表(常见国内域名)
file: ./rules/china_domain_list.txt
auto_reload: true
- tag: gfwlist # GFW 封锁域名列表(需要代理的域名)
file: ./rules/gfw_domain_list.txt
auto_reload: true
- tag: cdncn # 国内 CDN 域名列表(使用本地 DNS 解析更优)
file: ./rules/cdn_domain_list.txt
auto_reload: true
- tag: chinaip # 中国 IP 地址段
file: ./rules/china_ip_list.txt
auto_reload: true
- tag: gfwip # GFW 相关 IP 地址段(用于响应检测)
file: ./rules/gfw_ip_list.txt
auto_reload: true
- tag: adlist # 广告域名黑名单
file: ./rules/ad_domain_list.txt
auto_reload: true
- tag: hosts # 自定义 hosts 映射文件
file: ./hosts.txt
auto_reload: true
# ---------------------------------------------
# 插件列表(按顺序处理)
# ---------------------------------------------
plugins:
# ----- 1. Hosts 映射插件 -----
- tag: hosts
type: hosts
args:
hosts:
- "provider:hosts" # 从 data_providers 中加载 hosts
# ----- 2. ECS (EDNS Client Subnet) 自动获取插件 -----
- tag: ecs_auto
type: ecs
args:
auto: true # 自动获取客户端真实 IP 子网
force_overwrite: false # 不强制覆盖已有的 ECS
# ----- 3. ECS 局域网匹配插件(用于判断客户端是否在内网)-----
- tag: ecs_is_lan
type: query_matcher
args:
ecs: # 匹配以下私有/特殊 IP 段的 ECS
- "0.0.0.0/8"
- "10.0.0.0/8"
- "100.64.0.0/10"
- "127.0.0.0/8"
- "169.254.0.0/16"
- "172.16.0.0/12"
- "192.168.0.0/16"
- "224.0.0.0/3"
- "::1/128"
- "fc00::/7"
- "fe80::/10"
# ----- 4. 缓存插件(用于局域网客户端)-----
- tag: cache_lan
type: cache
args:
size: 1024 # 缓存条目数量
lazy_cache_ttl: 180 # 懒加载缓存 TTL(秒)
cache_everything: true # 缓存所有响应(包括错误)
lazy_cache_reply_ttl: 1 # 懒加载回复的临时 TTL
# ----- 5. 缓存插件(用于广域网查询)-----
- tag: cache_wan
type: cache
args:
size: 4096 # 缓存条目数量(比 LAN 更大)
compress_resp: true # 压缩响应以节省内存
lazy_cache_ttl: 180
cache_everything: true
lazy_cache_reply_ttl: 5
# ----- 6. TTL 修改插件(1 分钟)-----
- tag: ttl_1m
type: ttl
args:
minimal_ttl: 60 # 最小 TTL 60 秒
maximum_ttl: 3600 # 最大 TTL 1 小时
# ----- 7. TTL 修改插件(5 分钟)-----
- tag: ttl_5m
type: ttl
args:
minimal_ttl: 300 # 最小 TTL 5 分钟
maximum_ttl: 18000 # 最大 TTL 5 小时
# ----- 8. TTL 修改插件(1 小时)-----
- tag: ttl_1h
type: ttl
args:
minimal_ttl: 3600 # 最小 TTL 1 小时
maximum_ttl: 18000
# ----- 9. 黑洞插件(返回空响应,用于广告屏蔽)-----
- tag: black_hole
type: blackhole
args:
rcode: 0 # 返回 NOERROR 空应答
ipv4: "0.0.0.0" # A 记录返回 0.0.0.0
ipv6: "::" # AAAA 记录返回 ::
# ----- 10. 查询匹配:非域名格式(如纯 IP 查询)-----
- tag: query_is_non_domain
type: query_matcher
args:
domain:
- "keyword::" # 匹配空关键字(通常用于识别非标准域名)
# ----- 11. 查询匹配:本地域名(中国域名)-----
- tag: query_is_local_domain
type: query_matcher
args:
domain:
- "provider:chinalist"
# ----- 12. 查询匹配:非本地域名(GFW 列表域名)-----
- tag: query_is_non_local_domain
type: query_matcher
args:
domain:
- "provider:gfwlist"
# ----- 13. 查询匹配:国内 CDN 域名-----
- tag: query_is_cdn_cn_domain
type: query_matcher
args:
domain:
- "provider:cdncn"
# ----- 14. 查询匹配:广告域名-----
- tag: query_is_ad_domain
type: query_matcher
args:
domain:
- "provider:adlist"
# ----- 15. 响应匹配:响应中包含中国 IP-----
- tag: response_has_local_ip
type: response_matcher
args:
ip:
- "provider:chinaip"
# ----- 16. 响应匹配:响应中包含 GFW IP-----
- tag: response_has_gfw_ip
type: response_matcher
args:
ip:
- "provider:gfwip"
# ----- 17. 查询匹配:QType = 12 (PTR 记录)-----
- tag: qtype12
type: query_matcher
args:
qtype: [12]
# ----- 18. 查询匹配:QType = 65 (HTTPS 记录)-----
- tag: qtype65
type: query_matcher
args:
qtype: [65]
# ----- 19. 查询匹配:QType = 255 (ANY 查询)-----
- tag: qtype255
type: query_matcher
args:
qtype: [255]
# ----- 20. 上游转发:本地 DNS(国内)-----
- tag: forward_local
type: fast_forward
args:
upstream:
- addr: "udpme://119.29.29.29" # 腾讯 DNS(UDP + 多路复用)
- addr: "udpme://223.5.5.5" # 阿里 DNS(UDP + 多路复用)
- addr: "https://dns.alidns.com/dns-query" # 阿里 DoH
enable_pipeline: true
bootstrap: "223.6.6.6"
- addr: "https://doh.pub/dns-query" # DNSPod DoH
enable_pipeline: true
bootstrap: "119.29.29.29"
# ----- 21. 上游转发:远程 DNS(国际)-----
- tag: forward_remote
type: fast_forward
args:
upstream:
- addr: "udpme://1.1.1.1" # Cloudflare
- addr: "udpme://8.8.8.8" # Google
- addr: "udpme://9.9.9.9" # Quad9
- addr: "udp://185.222.222.222" # 备用 UDP
#enable_pipeline: true
#socks5: "127.0.0.1:1080" # 可通过 SOCKS5 代理(需自行配置)
# ----- 22. 主逻辑序列(核心处理流程)-----
- tag: main_sequence
type: sequence
args:
exec:
# 步骤 1:应用 hosts 映射
- hosts
# 步骤 2:处理非域名查询(如纯 IP 反向查询)
- if: "(query_is_non_domain)"
exec:
- _new_nxdomain_response # 返回 NXDOMAIN
- _return
# ============================================================
# 步骤 3:处理 PTR 查询(QType=12)- 修改后直接返回 NXDOMAIN
# 原因:Windows nslookup 默认会查询 PTR 记录,国内 DNS 对 PTR 支持不佳导致超时
# 直接返回 NXDOMAIN 可避免超时,不影响正常 A/AAAA 查询
# ============================================================
- if: "[qtype12]" # PTR 反向查询
exec:
- _no_ecs # 移除 ECS 信息
- _new_nxdomain_response # 直接返回 NXDOMAIN(域名不存在)
- _return
# 步骤 3b:处理 ANY 查询(QType=255)
- if: "[qtype255]" # ANY 查询
exec:
- _no_ecs
- forward_local
- ttl_1h
- _return
# 步骤 4:自动获取 ECS(EDNS Client Subnet)
- ecs_auto
- _edns0_filter_ecs_only # 过滤只保留 ECS 信息
# 步骤 5:根据 ECS 是否为局域网选择缓存
- if: ecs_is_lan
exec:
- cache_lan
- _no_ecs
else_exec:
- cache_wan
# 步骤 6:如果是局域网 ECS,再次移除 ECS(避免泄露)
- if: ecs_is_lan
exec:
- _no_ecs
# 步骤 7:广告域名直接黑洞并返回
- if: query_is_ad_domain
exec:
- black_hole
- ttl_1h
- _return
# 步骤 8:本地域名或 CDN 域名 → 使用本地 DNS,并检查响应是否被污染
- if: "(query_is_local_domain) || (query_is_cdn_cn_domain)"
exec:
- forward_local
- if: "(! response_has_gfw_ip)" # 如果响应中没有 GFW IP,则正常返回
exec:
- ttl_1m
- _return
# 步骤 9:GFW 列表域名 → 直接使用远程 DNS(代理)
- if: query_is_non_local_domain
exec:
- _prefer_ipv4 # 优先返回 IPv4 地址
- forward_remote
- ttl_5m
- _return
# 步骤 10:其余未分类域名 → 优先远程,如果响应包含中国 IP 则回落到本地 DNS
- _prefer_ipv4
- primary:
- forward_remote
- if: response_has_local_ip
exec:
- forward_local
- _return
secondary:
- forward_local
- _return
fast_fallback: 2500 # 主上游超时后快速切换到备用
always_standby: false
# 最后设置 TTL 为 5 分钟
- ttl_5m
# ---------------------------------------------
# DNS 服务器监听配置
# ---------------------------------------------
servers:
- exec: main_sequence # 使用上面定义的 main_sequence 处理逻辑
timeout: 6 # 查询超时时间(秒)
listeners:
- protocol: udp
addr: "0.0.0.0:53" # 监听所有网卡的 UDP 53 端口
- protocol: tcp
addr: "0.0.0.0:53" # 监听所有网卡的 TCP 53 端口
# ---------------------------------------------
# API 接口(可选,默认注释)
# ---------------------------------------------
#api:
#http: "0.0.0.0:9080" # 开启后可通过 HTTP 查看统计信息
至此,您已成功部署了一套基于 MosDNS-X 与 EasyMosdns 的 DNS 分流服务器。它不仅具备极高的性能,还内置了针对中国大陆地区的优化规则,可有效解决 DNS 污染问题,并提供 ECS 支持以加速 CDN 调度。如有任何自定义需求(如修改上游、调整缓存策略、添加广告过滤等),均可通过编辑 /etc/mosdns/config.yaml 轻松实现。
本教程以 Debian 12.14 在 VirtualBox / Hyper-V / VMware 中的虚拟机为例,采用桥接本机网卡方式,实现软路由功能(主要用于 LAN 侧转发 + 代理)。不需要配置 WAN 口,仅配置一个 LAN 接口。
下载 Debian 12.14 ISO 镜像(官方 netinst 或 full CD 均可)。
在虚拟机软件(VirtualBox / Hyper-V / VMware)中新建虚拟机:
安装过程中:
安装完成后重启,进入系统。
启用 Root SSH 密码登录:
nano /etc/ssh/sshd_config
找到并修改以下两行(去掉注释 #
PermitRootLogin yes
PasswordAuthentication yes
保存退出(Ctrl+O → Enter → Ctrl+X)。
重启 SSH 服务:
systemctl restart ssh
ip a
例如:
ens18
或者:
eth0
/etc/network/interfaces 管理网络。编辑配置文件:
nano /etc/network/interfaces
配置示例(静态 IP,适合软路由):
# This file describes the network interfaces
# and how to activate them
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# LAN 接口(根据虚拟机网卡名称替换见上方名称)
auto eth0 # 这里使用eth0示例
iface eth0 inet static # static静态
address 192.168.1.11/24 # 软路由 LAN IP
gateway 192.168.1.1 # 上级网关(通常是你的主路由器 IP)
dns-nameservers 119.29.29.29 223.5.5.5 #dns填入
iface eth0 inet6 dhcp #DHCPv6 有v6情况才写入
post-up sysctl -w net.ipv6.conf.eth0.accept_ra=2 >/dev/null 2>&1 #RA 获取默认v6路由上网
address:设置本机 LAN IP。gateway:上级路由器(主路由器)的 IP,用于软路由访问外网(可选,根据需求)。auto eth0
iface eth0 inet dhcp # dhcp顾名思义
systemctl restart networking
# 最好重启虚拟机
reboot
此时即可使用 SSH 客户端(推荐Netcatty;;或如 Xshell、MobaXterm、FinalShell 等),或cmd/powershell以 ssh root@IP 登录。
ip addr show
ip route
ping 119.29.29.29
使用 SSH 客户端以 root 登录虚拟机。
开启 IPv4/IPv6 转发(必需):
sudo cp /etc/sysctl.conf /etc/sysctl.conf.bk_$(date +%Y%m%d_%H%M%S) && \
sudo tee /etc/sysctl.conf << 'EOF'
net.ipv4.ip_forward=1
net.ipv4.conf.all.forwarding=1
net.ipv6.conf.all.forwarding=1
net.ipv4.tcp_congestion_control=bbr
net.core.default_qdisc=fq
EOF
sudo sysctl -p
sysctl net.ipv4.ip_forward
sysctl net.ipv6.ip_forward
应输出 net.ipv4.ip_forward = 1;net.ipv6.ip_forward = 1。
| 内容 | 链接 |
|---|---|
| 安装脚本 | https://github.com/picetor/openppp2_install |
| 原版仓库 | https://github.com/liulilittle/openppp2 |
| 改版,更多特性 | https://github.com/Miaocchi/openppp2 |
| 自编译版本,兼容openwrt | https://github.com/picetor/openppp2 |
直连 GitHub(海外服务器或网络良好)
wget -4 -O ppp_install.sh https://raw.githubusercontent.com/picetor/openppp2_install/main/ppp_install.sh && chmod +x ppp_install.sh && ./ppp_install.sh
使用Github加速
wget -4 -O ppp_install.sh https://git.apad.pro/https://raw.githubusercontent.com/picetor/openppp2_install/main/ppp_install.sh && chmod +x ppp_install.sh && ./ppp_install.sh
运行后进入交互菜单,根据提示选择客户端模式安装配置,需准备服务端信息、修改启动脚本/opt/ppp/ppp.sh;工作目录opt/ppp
项目地址: https://github.com/wnlen/clash-for-linux
Github直连
git clone --branch master --depth 1 https://github.com/wnlen/clash-for-linux.git
cd clash-for-linux
bash install.sh
Github加速
git clone --branch master --depth 1 ```
https://ghfast.top/https://github.com/wnlen/clash-for-linux.git
cd clash-for-linux
bash install.sh
安装完成后使用 clashon 启动,clashctl 管理订阅、节点等。详情看原仓库
192.168.1.50255.255.255.0192.168.1.11(Debian 的 IP)223.5.5.5、119.29.29.29;;或 Debian 的 IP 192.168.1.11 前提有dns服务器192.168.1.51255.255.255.0192.168.1.11(Debian 的 IP)223.5.5.5 等192.168.1.53192.168.1.11(Debian 的 IP)223.5.5.5 等在客户端上打开浏览器,访问 https://ip.skk.moe 或 https://ipcheck.ing/,显示的 IP 应为代理出口 IP(而非上级路由的 IP)。
也可在客户端命令行执行:
tracert 119.29.29.29 # Windows
traceroute 119.29.29.29 # Linux/macOS
第一跳应显示 192.168.1.11(Debian 软路由地址)。
+-------------+
| 上级路由 |
+-------------+
│
│ (桥接网络)
▼
+-------------+
| Debian 12.14|
| 软路由 |
+-------------+
│
├── openppp2
│ 或
└── Clash for Linux
│
│ (LAN 同网段)
▼
+-------------+
| 客户端 |
| (PC/手机等) |
+-------------+
后续常用操作:
ip addr、ip routenano /etc/network/interfacessystemctl restart networkingUDP2CAL 是一个双向、低延迟的局域网音频串流系统。支持 Android 手机麦克风采集发送到 Windows 虚拟声卡(正向),同时 PC 扬声器音频回传到手机播放(反向)。Opus 编解码、零软件降噪、声学回声消除、立体声/单声道自适应。全链路零堆分配,生产-消费双协程,P2P 独占通信防抢占。 - Raven777777/UDP2CAL
GitHub (github.com)