插件窝 干货文章 如何设置CentOS系统以禁用不安全的网络协议和服务

如何设置CentOS系统以禁用不安全的网络协议和服务

sudo 禁用 bash systemctl 635    来源:    2025-04-15

CentOS系统禁用不安全网络协议和服务指南

作为IT工程师,我将为您提供在CentOS系统上禁用不安全网络协议和服务的详细步骤,以提高系统安全性。

1. 禁用不安全的网络协议

1.1 禁用SSLv2和SSLv3

编辑OpenSSL配置文件:

sudo vi /etc/ssl/openssl.cnf

找到Protocol部分,确保包含以下内容:

MinProtocol = TLSv1.2
Options = -SSLv2, -SSLv3, -TLSv1, -TLSv1.1

1.2 禁用不安全的SSH协议

编辑SSH配置文件:

sudo vi /etc/ssh/sshd_config

修改或添加以下参数:

Protocol 2
HostKeyAlgorithms ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,rsa-sha2-512,rsa-sha2-256
KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com

1.3 禁用Telnet和FTP

sudo yum remove telnet-server vsftpd -y

2. 禁用不必要的服务

2.1 识别并禁用不必要的服务

sudo systemctl list-unit-files --type=service | grep enabled

禁用常见不必要的服务:

sudo systemctl disable rpcbind
sudo systemctl disable nfs
sudo systemctl disable rsh.socket
sudo systemctl disable rexec.socket
sudo systemctl disable rlogin.socket
sudo systemctl disable ypbind

2.2 禁用IPv6(如不需要)

编辑sysctl配置:

sudo vi /etc/sysctl.conf

添加以下内容:

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

应用更改:

sudo sysctl -p

3. 配置防火墙

3.1 使用firewalld限制访问

sudo systemctl enable firewalld
sudo systemctl start firewalld

3.2 只允许必要的端口

sudo firewall-cmd --permanent --remove-service=dhcpv6-client
sudo firewall-cmd --permanent --remove-service=ssh
sudo firewall-cmd --permanent --add-service=ssh --zone=work
sudo firewall-cmd --permanent --add-port=80/tcp --zone=work
sudo firewall-cmd --reload

4. 其他安全配置

4.1 禁用ICMP重定向

编辑sysctl配置:

sudo vi /etc/sysctl.conf

添加:

net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0

4.2 启用TCP SYN Cookie保护

/etc/sysctl.conf中添加:

net.ipv4.tcp_syncookies = 1

应用所有sysctl更改:

sudo sysctl -p

5. 验证配置

5.1 检查开放端口

sudo netstat -tulnp
sudo ss -tulnp

5.2 测试SSL/TLS配置

openssl s_client -connect localhost:443 -ssl3  # 应该失败
openssl s_client -connect localhost:443 -tls1_2  # 应该成功

5.3 使用安全扫描工具

sudo yum install nmap -y
nmap -sV --script ssl-enum-ciphers -p 443 localhost

6. 定期维护

  1. 定期更新系统:
sudo yum update -y
  1. 定期检查服务状态:
sudo systemctl list-unit-files --type=service | grep enabled
  1. 定期审计网络配置:
sudo netstat -tulnp
sudo firewall-cmd --list-all

通过以上步骤,您可以显著提高CentOS系统的网络安全性,禁用不安全的协议和服务,减少潜在的攻击面。