Windows Defender 防火牆 (原 Windows 防火牆) 為系統核心安全組件,預設啟用可阻擋未授權的輸入/輸出連線。特定場景 (測試網路服務、舊版遊戲/軟體相容、內網完全受控環境) 需暫時關閉。本文提供三種關閉方式與必讀風險提醒。



# 關閉所有設定檔防火牆 (需管理員權限)
netsh advfirewall set allprofiles state off
# 關閉特定設定檔
netsh advfirewall set privateprofile state off
netsh advfirewall set publicprofile state off
netsh advfirewall set domainprofile state off
# 開啟 (恢復)
netsh advfirewall set allprofiles state on
# 查看當前狀態
netsh advfirewall show allprofiles
# 關閉所有設定檔
Set-NetFirewallProfile -All -Enabled False
# 開啟
Set-NetFirewallProfile -All -Enabled True
# 查看狀態
Get-NetFirewallProfile | Format-Table Name, Enabled
# 允許特定埠號輸入 (如遊戲伺服器 27015 TCP/UDP)
netsh advfirewall firewall add rule name="Allow Game Server" dir=in action=allow protocol=TCP localport=27015
netsh advfirewall firewall add rule name="Allow Game Server UDP" dir=in action=allow protocol=UDP localport=27015
# 允許特定程式輸出
netsh advfirewall firewall add rule name="Allow MyApp" dir=out action=allow program="C:\Path\MyApp.exe"
PowerShell 執行 Get-NetFirewallProfile | Select Name, Enabled, DefaultInboundAction, DefaultOutboundAction,確認 Enabled 為 True (開啟) 或 False (關閉)。