主题
防火墙
CentOS 7 默认使用 firewalld 管理防火墙。firewalld 按区域组织规则,未指定 --zone 时使用默认区域。
服务管理
bash
# 启动
systemctl start firewalld
# 停止
systemctl stop firewalld
# 重启
systemctl restart firewalld
# 查看状态
systemctl status firewalld
# 开机启动
systemctl enable firewalld
# 禁止开机启动
systemctl disable firewalld规则
bash
# 查看活动区域
firewall-cmd --get-active-zones
# 查看默认区域的规则
firewall-cmd --list-all
# 永久开放 HTTP 服务
firewall-cmd --permanent --add-service=http
# 永久开放 TCP 端口
firewall-cmd --permanent --add-port=8388/tcp
# 重新加载永久规则
firewall-cmd --reload--permanent 只修改永久配置,需要重新加载后才会写入运行时配置。远程修改前应确认当前区域已放行 SSH,避免连接中断。
删除规则时,将对应命令中的 --add-service 或 --add-port 改为 --remove-service 或 --remove-port,然后重新加载。
