在 CentOS 中,防火墙一般是 firewalld(CentOS 7 及以上默认)。下面是常用的重启方法:
# 重启防火墙
systemctl restart firewalld
# 查看防火墙状态
systemctl status firewalld
# 设置开机自启(可选)
systemctl enable firewalld
如果只是想重新加载防火墙规则,可以用:
firewall-cmd --reload
这不会中断已有连接,比
restart更平滑。
如果是老版本 CentOS:
service iptables restart
或
/etc/init.d/iptables restart
firewall-cmd --state
返回 running 表示正在运行。
如果你是想关闭/开启防火墙或开放某个端口,也可以告诉我具体需求。