«

Linux防火墙配置

时间:2026-10-18 07:22     作者:emer     分类: 无


Linux防火墙配置

引言

云服务器安全不能只靠系统防火墙,开通端口是上线必经步骤。CentOS 7以上默认使用firewalld,很多新手忘了放行端口,导致网站、SSH、数据库从外部连不上。

firewalld常用命令

#查看防火墙状态
firewall-cmd --state

#查看已放行端口
firewall-cmd --list-ports

#永久放行80、443端口
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp

#重新加载生效
firewall-cmd --reload

#移除某个端口
firewall-cmd --permanent --remove-port=3306/tcp

区域概念

firewalld分public、internal等zone,默认public。--permanent写入永久规则,不加只对当前会话生效,重启失效。改完必须reload。

常用放行场景

注意事项

总结

firewalld核心:查看列表、永久加端口、reload生效。记住系统防火墙和云安全组两层都要放行,数据库端口绝不暴露公网,管理端口限制来源IP。

标签: Linux 防火墙 firewalld 服务器安全 端口放行