有些时候我们操作任务的时候需要关闭防火墙,比如我们常用的CentOS如何关闭防火墙呢?这里不同的版本号,他关闭防火墙的方法是不同的,这里我们对应各自的版本如果有需要可以参考。
1. CentOS 7/8/9(使用 firewalld)
临时关闭防火墙(重启后恢复)
sudo systemctl stop firewalld
此命令会立即停止防火墙服务,但系统重启后会自动重新启用。
永久禁用防火墙(重启后不启动)
sudo systemctl disable firewalld
此命令会禁止防火墙在系统启动时自动运行。
检查防火墙状态
sudo systemctl status firewalld
如果显示 inactive (dead),表示防火墙已关闭。
重新启用防火墙
sudo systemctl start firewalld # 启动防火墙
sudo systemctl enable firewalld # 设置开机自启
2. CentOS 6 及更早版本(使用 iptables)
临时关闭防火墙(重启后恢复)
sudo service iptables stop
立即停止 iptables 服务。
永久禁用防火墙(重启后不启动)
sudo chkconfig iptables off
禁止 iptables 在系统启动时自动运行。
检查防火墙状态
sudo service iptables status
如果显示 iptables: Firewall is not running,表示防火墙已关闭。
重新启用防火墙
sudo service iptables start # 启动防火墙
sudo chkconfig iptables on # 设置开机自启
这里,我们做一个总结:
系统版本 | 临时关闭防火墙 | 永久禁用防火墙 | 检查状态 |
---|---|---|---|
CentOS 7/8/9 | sudo systemctl stop firewalld |
sudo systemctl disable firewalld |
sudo systemctl status firewalld |
CentOS 6 及更早 | sudo service iptables stop |
sudo chkconfig iptables off |
sudo service iptables status |