要恢复 CentOS 系统中的 iptables 到出厂设置,你可以清空所有规则并重置默认策略。以下是具体步骤:
停止并禁用 firewalld 服务(如果正在运行):
sudo systemctl stop firewalld
sudo systemctl disable firewalld
清空所有 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
删除自定义的链(如果有):
sudo iptables -t nat -X
sudo iptables -t mangle -X
sudo iptables -X
重置默认策略:
sudo iptables -P INPUT DROP
sudo iptables -P FORWARD DROP
sudo iptables -P OUTPUT DROP
保存更改:
CentOS 默认不启用 iptables 持久化,所以你需要手动保存规则。你可以使用 service iptables save
命令来保存:
sudo service iptables save
或者,如果你使用的是 CentOS 7 或更高版本,并且已经安装了 iptables-services
包,可以使用以下命令:
sudo systemctl restart iptables
重启系统(可选): 为了确保所有更改生效,你可以重启系统:
sudo reboot
完成以上步骤后,你的 iptables 规则应该已经恢复到了出厂设置。请注意,这些步骤会清除所有自定义的防火墙规则,因此在执行之前请确保你不需要这些规则。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:centos防火墙如何恢复出厂设置