以下是CentOS防火墙安全加固的关键措施:
安装并启用防火墙
安装firewalld
并设置为开机自启:
sudo yum install firewalld
sudo systemctl start firewalld
sudo systemctl enable firewalld
配置默认区域与规则
work
或dmz
等更严格的策略:sudo firewall-cmd --set-default-zone=work
sudo firewall-cmd --permanent --add-port=22/tcp
sudo firewall-cmd --permanent --add-rich-rule='rule source address="192.168.1.0/24" service name="ssh" accept'
关闭不必要的服务与端口
禁用非必要服务(如telnet
、ftp
)及对应端口,减少攻击面:
sudo systemctl stop 服务名
sudo systemctl disable 服务名
sudo firewall-cmd --permanent --remove-service=服务名
强化SSH安全
/etc/ssh/sshd_config
,设置PermitRootLogin no
、PasswordAuthentication no
。启用SELinux
启用安全增强模块,限制进程权限:
sudo setenforce 1
sudo sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/config
日志与监控
sudo firewall-cmd --set-log-denied=all
/var/log/secure
等日志,识别潜在攻击。定期更新与规则优化
sudo yum update
。注:部分操作需根据实际业务调整,测试环境验证后再应用到生产环境。