萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 電腦基礎知識 >  >> 健康知識

善用 Netsh 命令快速診斷與配置 Windows 防火牆

Netsh:防火牆配置的命令列瑞士刀

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,讓防火牆配置從「點下一步」進化為「基礎設施即程式碼」。

copyright © 萬盛學電腦網 all rights reserved