在 VPS 上管理 /etc/nftables.conf 中的端口转发:列出、添加、删除转发规则,以及语法检测后加载并重启 nftables。
功能:
使用:
# 下载并运行(需 root,因会写 /etc/nftables.conf)
curl -sSL "https://raw.githubusercontent.com/mryee2023/scripts/refs/heads/main/nftables-forward-manager.sh" -o nftmgr.sh
chmod +x nftmgr.sh
sudo ./nftmgr.sh
指定配置文件(例如本地测试):
# 使用当前目录的 nftables.conf 测试
NFTABLES_CONFIG=./nftables.conf sudo ./nftmgr.sh
默认配置文件路径:/etc/nftables.conf。修改配置需 root;测试时可设置 NFTABLES_CONFIG 指向本地文件。
通过 nftables 对指定端口封锁大陆 IP(TCP/UDP)。
使用:
curl -sSL "https://raw.githubusercontent.com/mryee2023/scripts/refs/heads/main/gfw-nft.sh" -o gfw-nft.sh
chmod +x gfw-nft.sh
sudo ./gfw-nft.sh -u # 初始化/更新大陆 IP 库(首次必须执行)
sudo ./gfw-nft.sh -a 8388 # 封锁端口 8388
sudo ./gfw-nft.sh -d 8388 # 解封端口 8388
sudo ./gfw-nft.sh -l # 查看当前封锁端口列表
持久化: 规则保存在 /etc/nftables/gfw.nft,需在 /etc/nftables.conf 末尾添加以下内容才能开机自动生效:
include "/etc/nftables/gfw.nft"