Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

以 netsh advfirewall 命令列全掌控 Windows Server 2008 防火牆

編輯:Windows Server 常見問題解答

Windows Server 2008 引入進階防火牆,支援雙向過濾、IPsec 整合與精細規則。透過 netsh advfirewall 命令列介面,管理員能更快速、可腳本化、甚至在 Core 模式下完整配置防火牆。

為何選擇命令列配置?

  • 速度更快:熟練指令後,配置效率遠勝圖形介面。
  • 可腳本自動化:批量部署、跨 IPv4/IPv6 同步設定。
  • 無圖形介面時仍可用:Server Core 環境下的唯一選擇。

核心指令速查

指令功能範例
help / ?顯示當前上下文所有可用選項netsh advfirewall ?
consec連線安全規則(IPsec VPN)netsh advfirewall consec add ...
show檢視防火牆狀態、別名、模式show mode
export匯出完整設定至檔案export "c:\fw.wfw"
firewall管理輸入/輸出規則firewall add rule name="Allow Messenger" dir=in program="c:\msg.exe" action=allow
import從檔案還原設定import "c:\fw.wfw"
reset重設為預設原則(不可復原,慎用)reset
set修改全域設定(如日誌、通知、預設動作)set global statefulftp enable

實戰範例:新增與刪除規則

# 允許 Messenger 入站
netsh advfirewall firewall add rule name="Allow Messenger" dir=in program="c:\program files\messenger\msmsgs.exe" action=allow

# 刪除本地埠 21 所有 TCP 入站規則
netsh advfirewall firewall delete rule name=all protocol=tcp localport=21

進階提示

  • 善用 dump 產生設定腳本,利於版本控管與部署。
  • 結合群組原則(GPO)推送腳本,實現企業級統一管理。
  • 定期 export 備份,變更前先備份,出錯即時 import 回滾。
Copyright © Windows教程網 All Rights Reserved