首先查看系统当前运行的所有服务:
systemctl list-unit-files --type=service --state=enabled
netstat -tulnp
ss -tulnp
# 打印服务
sudo systemctl disable cups
# 蓝牙服务
sudo systemctl disable bluetooth
# Avahi (zeroconf/mDNS服务)
sudo systemctl disable avahi-daemon
# NFS相关服务(如果不使用NFS)
sudo systemctl disable nfs-server
sudo systemctl disable rpcbind
# 邮件服务(如postfix)
sudo systemctl disable postfix
# 自动更新服务(如需要手动更新)
sudo systemctl disable dnf-automatic
# 编辑/etc/sysctl.conf
echo "net.ipv6.conf.all.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6 = 1" | sudo tee -a /etc/sysctl.conf
# 应用设置
sudo sysctl -p
# 创建模块黑名单文件
echo "install dccp /bin/false" | sudo tee -a /etc/modprobe.d/disable-unused.conf
echo "install sctp /bin/false" | sudo tee -a /etc/modprobe.d/disable-unused.conf
echo "install rds /bin/false" | sudo tee -a /etc/modprobe.d/disable-unused.conf
echo "install tipc /bin/false" | sudo tee -a /etc/modprobe.d/disable-unused.conf
# 安装防火墙(如果未安装)
sudo yum install firewalld -y
sudo systemctl enable firewalld
sudo systemctl start firewalld
# 默认拒绝所有传入连接
sudo firewall-cmd --set-default-zone=drop
sudo firewall-cmd --runtime-to-permanent
sudo yum remove telnet rsh rlogin ypbind tftp
编辑 /etc/ssh/sshd_config
:
Protocol 2
PermitRootLogin no
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 0
AllowUsers [你的用户名]
然后重启SSH服务:
sudo systemctl restart sshd
sudo reboot
/var/log/messages
, journalctl -xe
)确认没有异常以上配置可根据实际业务需求进行调整,某些服务在特定环境下可能是必需的。