Windows 防火牆 (SP2+) 透過 netsh firewall 指令集提供完整的查詢與設定能力,適合腳本自動化、遠端管理、精確除錯。
| 指令 | 功能 |
|---|---|
show allowedprogram | 顯示允許的程式清單 |
show config | 顯示完整防火牆配置 |
show currentprofile | 顯示目前設定檔(域/私人/公用) |
show icmpsetting | 顯示 ICMP 設定(如允許 Ping) |
show logging | 顯示日誌記錄設定 |
show multicastbroadcastresponse | 顯示多播/廣播回應設定 |
show notifications | 顯示通知設定 |
show opmode | 顯示操作模式(開啟/關閉/僅通知) |
show portopening | 顯示開放連接埠清單 |
show service | 顯示允許的服務 |
show state | 顯示防火牆當前狀態 |
| 指令 | 功能 |
|---|---|
set allowedprogram | 編輯允許程式清單 |
set icmpsettings | 編輯 ICMP 設定 |
set logging | 編輯日誌記錄設定 |
set notifications | 編輯通知設定 |
set opmode | 編輯操作模式(enable/disable/notifynotify) |
set portopening | 編輯開放連接埠 |
set service | 編輯允許服務 |
# 開放 TCP 80 給所有介面
netsh firewall set portopening TCP 80 "Web Server" ENABLE ALL
# 允許特定程式通訊
netsh firewall set allowedprogram "C:\App\MyServer.exe" "My Server" ENABLE ALL
# 關閉防火牆(不建議生產環境)
netsh firewall set opmode DISABLE
show config 輸出為文字檔,納入變更管理文件。掌握 Netsh,讓防火牆配置從「點下一步」進化為「基礎設施即程式碼」。