安装与开机自启
1. 放置二进制
Section titled “1. 放置二进制”推荐路径:/usr/bin/pcdn-detect(LuCI 面板的默认 bin_path 也是它)。
2. 初始化配置
Section titled “2. 初始化配置”mkdir -p /etc/pcdn-detect/usr/bin/pcdn-detect --init-config /etc/pcdn-detect/usr/bin/pcdn-detect -T -c /etc/pcdn-detect/pcdn-detect.toml至少修改两项:
[capture]interface = "br-lan" # 必须是 LAN 侧网桥,能看到设备 MAC
[log]level = "info" # 想看到告警与封禁记录时3. 配置 procd 服务
Section titled “3. 配置 procd 服务”不用 LuCI 面板时,手写 /etc/init.d/pcdn-detect:
#!/bin/sh /etc/rc.commonSTART=99USE_PROCD=1
start_service() { procd_open_instance procd_set_param command /usr/bin/pcdn-detect -c /etc/pcdn-detect/pcdn-detect.toml procd_set_param stdout 1 procd_set_param stderr 1 procd_set_param respawn procd_close_instance}
reload_service() { local pids pids="$(pidof pcdn-detect 2>/dev/null)" [ -n "$pids" ] && kill -HUP $pids}chmod +x /etc/init.d/pcdn-detect/etc/init.d/pcdn-detect enable/etc/init.d/pcdn-detect startlogread -e pcdn-detect # 查看日志reload_service 会给进程发 SIGHUP,实现原地热重载;脚本没有实现该函数时,reload 不会发送信号:
/etc/init.d/pcdn-detect reload用 LuCI 面板时
Section titled “用 LuCI 面板时”装了 luci-app-pcdn-detector 就不需要手写脚本,它自带 /etc/init.d/pcdn-detector:
- 从 UCI(
/etc/config/pcdn-detector)读取enabled/bin_path/config_path/extra_args; - 配置文件不存在时,自动调用
pcdn-detect --init-config生成,并把interface填成br-lan; respawn 3600 5 5,崩溃后自动拉起;- 日志走 stdout,syslog tag 为
pcdn-detect。
此时通过 LuCI 或 /etc/init.d/pcdn-detector {start|stop|restart|reload|isrunning|version} 管理。
4. 前台调试
Section titled “4. 前台调试”排查问题时先停服务,前台带高日志等级运行:
/etc/init.d/pcdn-detector stoppcdn-detect -c /etc/pcdn-detect/pcdn-detect.toml -L -n 10 -t 30s命令行参数优先于配置文件,适合临时放宽条件验证链路。
5. 升级与卸载
Section titled “5. 升级与卸载”- 有面板:用「下载/更新」页,安装后自动执行
-v自检,失败回滚到.bak。详见 界面使用与运维。 - 无面板:覆盖
/usr/bin/pcdn-detect后/etc/init.d/pcdn-detect restart。旧进程退出时会 兜底解封并清理规则,因此重启不会遗留封禁。 - 卸载:先
stop(触发兜底解封与规则清理),再删除二进制、init 脚本与配置目录。 直接kill -9不会清理,nftables 后端下次启动会重建表,iptables 后端会清空专用链,hook后端需自行幂等处理。
6. 与其他服务共存
Section titled “6. 与其他服务共存”- 抓包是只读的,不会改动任何系统状态,只消耗少量 CPU。混杂模式(默认开启)额外覆盖的是
「设备 ↔ 设备」纯二层互访帧,对判定与封禁没有作用;
br-lan这类网桥接口上可以设为promisc = false,LAN 内互访流量大时能明显减少进入用户态的报文量。监听物理端口、或本机只做 AP / 交换(流量经网桥穿过、目的地是其它设备)时保持默认true。 nftables后端要求 LAN 侧是网桥(ether saddr仅 bridge / netdev 族可用)。纯路由环境 请改用iptables或hook后端。- 与其他防火墙脚本共存时,注意专用链名(
ban_chain/upnp_chain)不要与自己已有的链重名。