在 CentOS(以及一般 Linux 服务器)上防御 exploit(漏洞利用),核心思路是:减少攻击面 + 及时修补 + 限制权限 + 监控异常。下面按实用优先级给你一套防护方案。
yum update -y
# 或 CentOS 8+/Stream
dnf update -y
yum install yum-cron -y
systemctl enable yum-cron
systemctl list-unit-files --type=service | grep enabled
关闭不必要的:
systemctl disable --now telnet vsftpd rsh
编辑 /etc/sysctl.conf:
net.ipv4.tcp_syncookies = 1
net.ipv4.conf.all.rp_filter = 1
kernel.randomize_va_space = 2
sysctl -p
sed -i 's/^PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
systemctl restart sshd
useradd admin
passwd admin
usermod -aG wheel admin
PasswordAuthentication no
firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --remove-service=ftp
firewall-cmd --reload
firewall-cmd --permanent --add-rich-rule='rule service name=ssh limit value=3/m accept'
或使用 fail2ban:
yum install epel-release -y
yum install fail2ban -y
systemctl enable --now fail2ban
getenforce
setenforce 1
配置文件:
/etc/selinux/config
SELINUX=enforcing
CentOS 默认用 SELinux,不要关。
DELETE FROM mysql.user WHERE User='root' AND Host='%';
chmod 644 /etc/passwd
chmod 600 /etc/shadow
/var/log/secure
/var/log/messages
journalctl -xe
yum install aide -y
aide --init
如果你指的是某个具体 CentOS exploit(如:
✅ 正确做法是:
CentOS 防 exploit = 及时更新 + 最小权限 + SELinux + 防火墙 + 日志监控
如果你有:
我可以直接给你针对性命令。