Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 服務器安全加固六大核心策略:從網絡層到訪問控制的實戰指南

編輯:Linux 教學

面對持續演進的網絡威脅,Linux 服務器安全加固需構建纵深防禦體系。本文提煉六大高收益、低侵入性的加固策略,均經生產環境驗證,可立即落地。

1. 禁用 ICMP Echo 回應——隱藏存活探測面

# 臨時生效
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
# 永久生效
echo "net.ipv4.icmp_echo_ignore_all = 1" >> /etc/sysctl.conf
sysctl -p

原理:阻斷攻擊者通過 Ping 掃描確認主機存活,大幅降低被針對性攻擊概率。注意:可能影響依賴 Ping 的監控系統,需協調調整監控探針(改用 TCP/HTTP 健康檢查)。

2. 禁用 Ctrl+Alt+Delete 重啟——防物理接觸誤操作

# RHEL 6/7 / CentOS 6/7
sed -i 's/^ca::ctrlaltdel:/#ca::ctrlaltdel:/' /etc/inittab
# RHEL 7+ / CentOS 7+ (systemd)
systemctl mask ctrl-alt-del.target
systemctl daemon-reload

防止機房人員誤觸或惡意重啟導致服務中斷。

3. 限制 Shell 歷史記錄——減輕憑證洩露後果

# /etc/profile
export HISTSIZE=30          # 僅保留 30 條
export HISTFILESIZE=30
export HISTCONTROL=ignorespace:ignoredups  # 忽略空格開頭與重複命令
# 立即生效
source /etc/profile

平衡審計需求與風險控制;高安全環境可設 HISTSIZE=0 完全禁用。

4. 清理預設冗餘賬號——縮小攻擊面

# 刪除無用用戶
for u in adm lp sync shutdown halt news uucp operator games gopher; do userdel $u 2>/dev/null; done
# 刪除無用組
for g in adm lp news uucp games dip pppusers popusers slipusers; do groupdel $g 2>/dev/null; done

保留 root、系統服務賬號 (sshd, postfix 等) 及業務專用賬號。

5. SELinux 策略決策:關閉 vs 精細管理

# 檢查狀態
getenforce
# 修改為 Permissive (記錄不阻擋) —— 推薦過渡方案
sed -i 's/^SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
# 或完全關閉 (需重啟)
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

建議:新系統上線前在 Permissive 模式運行 1-2 週,分析 ausearch -m avc 產生的策略違規,定製專用模塊後再切 Enforcing;無專業團隊支撐的中小環境,Permissive 是風險與可用性的平衡點。

6. 部署 TCP Wrappers 雙層訪問控制

配合 iptables (網絡層) 形成「包過濾 + 服務層 ACL」雙重保障。

# /etc/hosts.allow  (優先匹配)
sshd: 222.90.66.4 61.185.224.66 .softpark.com
vsftpd: 192.168.60.0/255.255.255.0
# /etc/hosts.deny  (默認拒絕)
ALL: ALL

關鍵點:僅對鏈接 libwrap 的服務生效 (sshd, vsftpd, portmap, xinetd 等);需結合 systemctl status sshd | grep -i libwrap 驗證。

驗證清單

  • ping → 無回應
  • ssh -v 非白名單 IP → Connection refused
  • last -x reboot → 無 Ctrl+Alt+Delete 重啟記錄
  • history | wc -l → ≤ 30
  • getent passwd adm lp sync → 無輸出
  • getenforce → Permissive/Disabled

安全加固非一次性動作,需納入變更管理流程,定期複核審計日誌,持續收斂攻擊面。

Copyright © Windows教程網 All Rights Reserved