在 CentOS 系统中,使用 iptables
命令可以管理防火墙规则。如果你想清除所有的 iptables
规则,可以使用以下命令:
清空所有链的规则:
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -t nat -F
sudo iptables -t mangle -F
sudo iptables -F
sudo iptables -X
这些命令的作用是:
-X
)。-F
)。nat
表中的所有规则 (-t nat -F
)。mangle
表中的所有规则 (-t mangle -F
)。保存更改:
在 CentOS 7 及更高版本中,iptables
规则在重启后不会自动保存。你可以使用 firewall-cmd
来管理防火墙并使其规则持久化:
停止 firewalld 服务(如果正在运行):
sudo systemctl stop firewalld
禁用 firewalld 开机自启:
sudo systemctl disable firewalld
使用 iptables-save
和 iptables-restore
来手动保存和恢复规则(可选)。
使用 firewall-cmd
(可选):
如果你想使用 firewall-cmd
来管理防火墙并使其规则持久化,可以使用以下命令:
查看当前区域配置:
sudo firewall-cmd --list-all
重载防火墙配置:
sudo firewall-cmd --reload
停止 firewalld 服务(如果正在运行):
sudo systemctl stop firewalld
禁用 firewalld 开机自启:
sudo systemctl disable firewalld
通过以上步骤,你可以清除 CentOS 系统中的 iptables
规则并确保它们不会在重启后自动应用。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>