伺服器/對外主機應遵循「只開必要埠,其餘全擋」。典型最小集合:21 (FTP)、80/443 (Web)、3389 (RDP)、53 (DNS)。ICMP Echo Request (Ping) 建議關閉,減少偵察面。
wf.msc 開啟「具有進階安全性的 Windows 防火牆」。
80,443,3389,21 (依需求增減) → 下一步。
Allow_Web_RDP_FTP,描述:僅開放必要服務埠 → 完成。
# 開放必要 TCP 埠
$ports = 21, 80, 443, 3389
foreach ($p in $ports) {
New-NetFirewallRule -DisplayName "Allow_TCP_$p" -Direction Inbound -Protocol TCP -LocalPort $p -Action Allow -Profile Domain,Private,Public
}
# 禁用 Ping (ICMPv4 Echo Request)
New-NetFirewallRule -DisplayName "Block_ICMPv4_Echo_Request" -Direction Inbound -Protocol ICMPv4 -IcmpType 8 -Action Block -Profile Domain,Private,Public
# 驗證
Get-NetFirewallRule -DisplayName "Allow_TCP_*", "Block_ICMPv4_Echo_Request" | Format-Table Name, Enabled, Direction, Action, Protocol, LocalPort
netstat -an | findstr "LISTEN" 確認埠口監聽。nmap -p 21,80,443,3389 / Test-NetConnection -Port 3389 -ComputerName 確認開放;ping 確認無回應。「只開所需、拒絕其餘、記錄審計」是防火牆配置的鐵律。定期複核規則清單,刪除廢棄/測試規則,保持規則集乾淨、可審計、可解釋。