在CentOS系统中,防火墙是保护系统安全的重要工具。CentOS默认使用firewalld
作为防火墙管理工具,它提供了一个动态管理防火墙规则的方法,相比于iptables
,firewalld
更加人性化,支持在线修改规则而不需要重启。以下是CentOS防火墙配置的一些技巧:
启动和检查防火墙状态:
systemctl start firewalld
systemctl status firewalld
或使用firewall-cmd
命令:
firewall-cmd --state
添加、修改和删除防火墙规则:
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --remove-port=8080/tcp --permanent
firewall-cmd --reload
设置默认区域:
firewall-cmd --set-default-zone=public
查看开放端口:
firewall-cmd --zone=public --list-ports
虽然firewalld
是首选的防火墙管理工具,但了解iptables
的基本配置也是必要的。
查看当前iptables规则:
iptables -L -n
添加规则:
iptables -A INPUT -p tcp --dport 22 -j ACCEPT # 允许SSH端口
保存iptables规则:
service iptables save
firewalld
使用区域来定义不同的网络环境,如公共网络、内部网络和信任网络等。每个区域都有自己的防火墙规则集合。
查看所有区域:
firewall-cmd --get-zones
设置默认区域:
firewall-cmd --set-default-zone=public
firewalld
支持动态更新防火墙规则,这意味着你可以在运行时添加、删除或修改规则,而无需重新加载整个防火墙配置。
配置SELinux: SELinux是CentOS中的安全增强模块,可以帮助保护系统免受攻击。
setenforce 1
更新软件包: 定期更新系统中的软件包可以帮助修补安全漏洞并提高系统安全性。
yum update
安装安全工具: 可以使用许多工具来帮助加强CentOS系统的安全性,如fail2ban来保护系统免受暴力破解攻击。
yum install fail2ban
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:centos防火墙如何配置