建置安全的 Linux 伺服器,首重熟悉網路服務相關配置檔的用途與安全設定。Linux 的 TCP/IP 參數主要透過純文字檔案管理,雖可用 linuxconf/netconf 等工具輔助,但理解檔案結構才能精準控制與稽核。本文梳理核心配置檔並給出加固建議。
| 檔案路徑 | 用途 | 關鍵參數範例 |
|---|---|---|
/etc/conf.modules(舊)/etc/modules.conf / /etc/modprobe.d/ | 核心模組載入參數,特別是多網卡(ISA 需指定 IO、IRQ) | alias eth0 3c509options 3c509 io=0x300,0x320 |
/etc/HOSTNAME | 主機完整網域名稱(FQDN) | deep.openarch.com |
/etc/sysconfig/network-scripts/ifcfg-ethN | 各網卡 IP、掩碼、閘道、啟動協議 | DEVICE=eth0IPADDR=208.164.186.1NETMASK=255.255.255.0ONBOOT=yesBOOTPROTO=none |
/etc/resolv.conf | DNS 解析器設定:搜尋域、名稱伺服器順序 | search openarch.comnameserver 208.164.186.1nameserver 208.164.186.2 |
/etc/host.conf | 主機名解析順序與防偽裝 | order bind,hostsmulti onnospoof on |
/etc/sysconfig/network | 全域網路參數:啟用轉發、主機名、預設閘道 | NETWORK=yesFORWARD_IPV4=yesGATEWAY=192.168.1.1 |
/etc/hosts | 靜態名稱對應表(DNS 前優先查詢) | 127.0.0.1 localhost208.164.186.1 gate.openarch.com gate |
/etc/inetd.conf / /etc/xinetd.d/ | 超級守護進程服務啟用控制(舊版 inetd / 新版 xinetd) | 以 # 註解停用 ftp、telnet、finger 等高風險服務 |
# 僅保留必須服務,其餘全部註解
# 修改後重載
killall -HUP inetd # 或 systemctl reload xinetd
chmod 600 /etc/inetd.conf
chown root:root /etc/inetd.conf
chattr +i /etc/inetd.conf # 防竄改,需改時先 chattr -i
如 sendmail、named、httpd 等,使用 chkconfig 或 systemctl 關閉非必要服務:
chkconfig --level 35 named off
systemctl disable --now telnet.socket
/etc/rc.d/init.d/network restart # SysVinit
# 或
systemctl restart NetworkManager # systemd
/etc/hosts 必含本機 FQDN 解析,防單點 DNS 故障導致服務啟動卡頓;netstat -tulnp 與 ss -tulnp,確認僅預期埠對外開放;iptables/nftables 做主機層防火牆,實現纏繞防禦。