此教程用于教你如何编译 OpenWrt 同时加入相关防共享检测工具(UA2F、UA3F、Clash)。
对于不想编译的朋友,直接参见 https://github.com/SunBK201/UA3F/releases 下载对应的 ipk 软件包安装即可。
具体教程见:猴子也能看懂的 UA3F 使用教程
https://github.com/SunBK201/UA3F
Welcome to the OpenWrt Project
https://github.com/CoolLoong/AutoBuild-Actions
https://github.com/DFlinmo/Actions-immortalWrt-UA2F
https://github.com/SunBK201/OpenWrt-R4S-glibc
<aside> ⚠️ 仅供参考
</aside>
<aside> 💡 如果是使用 Clash 加密 + TTL 伪装方案,无需手动编译,直接访问 https://firmware-selector.openwrt.org 下载所需固件即可,刷入固件后,可以手动安装 Clash,并配置防火墙。
</aside>
<aside> ⚠️ 请保证全局魔法环境,编译失败的大多数原因是网络问题。
</aside>
<aside> ⚠️ 如果你使用的是虚拟机进行编译,建议使用 Clash For Windows 并开启 TUN Mode 即可接管虚拟机流量进行代理。
</aside>
<aside> ⚠️ 编译操作系统建议使用 Ubuntu 22.04 LTS,操作系统语言建议使用英文。
</aside>
# 系统软件包更新
sudo apt-get -y update
sudo apt-get -y upgrade
# 安装依赖关系与编译工具链
sudo apt install build-essential clang flex bison g++ gawk \\
gcc-multilib g++-multilib gettext git libncurses-dev libssl-dev \\
python3-distutils python3-setuptools rsync swig unzip zlib1g-dev file wget
# 下载 OpenWrt 源码 (下面二者选其一)
git clone <https://github.com/openwrt/openwrt.git> && cd openwrt
git clone <https://github.com/coolsnowwolf/lede> && cd lede
~~# openwrt-22.03 已将 iptables 移除,为避免兼容性问题,暂时切换到 openwrt-21.02~~
~~git checkout openwrt-21.02~~
git checkout openwrt-23.05
# 更新 feeds 软件源
./scripts/feeds update -a
# 安装 feeds 软件包
./scripts/feeds install -a
git clone <https://github.com/SunBK201/UA3F.git> package/UA3F
make menuconfig # 勾选 Network->Web Servers/Proxies->ua3f
<aside> ⚠️ UA2F 与 UA3F 二选一
</aside>
git clone <https://github.com/Zxilly/UA2F.git> package/UA2F
make menuconfig
~~# 选上三个模块: libmnl, libnetfilter-queue, iptables-mod-nfqueue, 搜索就能找到
# network->firewall->iptables-mod-filter
# network->firewall->iptables-mod-ipopt
# network->firewall->iptables-mod-u32~~
# 勾选上ua2f,在配置面板中搜索就可找到
# network->Routing and Redirection
# 然后保存退出
# 这一步可能时间比较长,要耐心
make kernel_menuconfig
# 然后将
# Networking support ->
# Networking options ->
# Network packet filtering framework (Netfilter) ->
# Core Netfilter Configuration ->
# Netfilter NFNETLINK interface
# Netfilter LOG over NFNETLINK interface
# Netfilter connection tracking support
# Connection tracking netlink interface
# NFQUEUE and NFLOG integration with Connection Tracking 打开
<aside>
⚠️ 上一步可以跳过,但需要在对应内核 config 文件中手动加入 CONFIG_NETFILTER_NETLINK_GLUE_CT=y,除非你知道这是什么,否则不建议你手动添加
</aside>
在 make menuconfig 中,使用 option 设置。

**LuCI**
**--> 1. Collections**
--> luci
**--> 2. Modules
--> Translations**
--> Chinese Simplified (zh_Hans)
--> luci-compat
<aside> ⚠️ Clash 的加入针对 DPI 检测,如果没有 DPI 检测无需加入
</aside>
<aside> ⚠️ 如果你的路由器性能不足可以使用 ShellClash 来代替 OpenClash
</aside>
svn checkout <https://github.com/vernesong/OpenClash/trunk/luci-app-openclash> package/luci-app-openclash
make menuconfig
# 选择以下模块
**LuCI**
**--> 1. Collections**
--> luci
--> luci-compat
**--> 3. Applications**
--> luci-app-openclash
Base system
--> Customize busybox options
--> dnsmasq-full (cancel the above 'dnsmasq' option)
<aside> ⚠️ 通过 IPID 进行检测的可能性极低,此模块不建议加入。
</aside>
~~git clone <https://github.com/CHN-beta/rkp-ipid.git> package/rkp-ipid
make menuconfig
# 选上三个模块: kmod-ipt-u32, iptables-mod-u32, iptables-mod-filter, 搜索就能找到
# 然后勾选上 ipid
# 位于 kernel-modules->Other modules 下
# 然后保存退出~~
make menuconfig
# 选上两个模块: iptables-mod-ipopt, kmod-ipt-ipopt,搜索就能找到
# 然后保存退出
Network -> ipset
Firewall -> iptables-mod-conntrack-extra
# 预下载编译所需的软件包
make download -j$(nproc) V=s
# 编译
make -j$(nproc) || make -j1 || make -j1 V=s
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin make -j$(($(nproc) + 1)) || PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin make -j1 V=s
编译后的固件文件在:openwrt/bin/targets 下面。
到这里编译就结束了,刷入固件后就可以进行以下配置。
OpenWRT 系统设置, 勾选 Enable NTP client(启用 NTP 客户端)和 Provide NTP server(作为 NTP 服务器提供服务)ntp1.aliyun.com、time1.cloud.tencent.com、stdtime.gov.hk 、pool.ntp.org<aside> ⚠️ 写于 2025.11,目前下面的大多数配置已无需加入,因为大部分插件已实现自动配置
</aside>
<aside> ⚠️ 请按照以下规则顺序,若顺序与以下不符,可能配置不起效。
</aside>
https://github.com/SunBK201/UA3F