Files
2025-12-08 08:56:23 +08:00

43 lines
1.1 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# UFW 防火墙规则清除脚本
# 适用于 Ubuntu 22.04
# 检查是否以root权限运行
if [ "$EUID" -ne 0 ]; then
echo "请使用 sudo 运行此脚本"
exit 1
fi
echo "========================================="
echo "开始清除 UFW 防火墙规则"
echo "========================================="
# 1. 禁用UFW
echo ">>> 禁用 UFW 防火墙"
ufw disable
echo "执行: ufw disable"
# 2. 重置UFW到出厂默认状态删除所有规则
echo ">>> 重置 UFW 到出厂默认状态"
echo "y" | ufw reset
echo "执行: ufw reset"
# 3. 恢复默认策略
echo ">>> 恢复默认策略"
ufw default deny incoming
echo "执行: ufw default deny incoming"
ufw default allow outgoing
echo "执行: ufw default allow outgoing"
# 4. 显示当前状态
echo "========================================="
echo "UFW 防火墙规则已全部清除"
echo "当前状态:"
echo "========================================="
ufw status verbose
echo ""
echo "清除完成UFW 已禁用,所有自定义规则已删除"
echo "如需重新启用,请运行: sudo ufw enable"