2008-04-03 11:25:31 Kenny

netsh

 

http://support.microsoft.com/kb/947709/zh-tw

INTRODUCTION

netsh advfirewall 防火牆 將命令列內容可在 Windows Server 2008 以及 Windows Vista 中。 在此內容中提供對控制 Windows 防火牆行為以舊版 Windows 作業系統中內容的 netsh 防火牆 所提供的功能。

在此內容中也提供功能為更精確的控制項的防火牆規則。 下列每個設定檔設定這些規則包括:
網域
私密
公用
在未來的 Windows 作業系統版本可能會被取代 netsh 防火牆 將命令列內容。 我們建議您使用 advfirewall netsh firewall 內容, 以便控制項防火牆行為。

本篇文章說明如何使用 advfirewall netsh firewall 內容, 而不是 netsh firewall 內容, 以便控制 Windows 防火牆行為在 Windows Server 2008 及 Windows Vista 中。

回此頁最上方

其他相關資訊

在下列表格提供一些常用命令的範例。 您可以使用這些範例可幫助您將從較舊的 netsh 防火牆 內容遷移到新 advfirewall netsh 防火牆 內容。

除此之外, 提供 advfirewall netsh 命令, 您可以用來取得內嵌詳細說明。

回此頁最上方

範例 1: 啟用某個程式

舊的指令 新命令
netsh 防火牆新增 allowedprogram C:\MyApp\MyApp.exe ENABLE 「 [ 我的應用程式 」 netsh advfirewall 防火牆新增規則名稱允許 program=öC:\MyApp\MyApp.exeö 啟用 = = 在動作 = öMy Applicationö dir = yes
netsh 防火牆新增 allowedprogram program=C:\MyApp\MyApp.exe 名稱 = ENABLE 範圍 = " My Application " 模式 = CUSTOM addresses=157.60.0.1,172.16.0.0/16,LocalSubnet 設定檔 = 網域 netsh advfirewall 防火牆新增規則名稱 = yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet 設定檔允許 program=öC:\MyApp\MyApp.exeö 啟用 = = 在動作 = öMy Applicationö dir = 網域
netsh 防火牆新增 allowedprogram program=C:\MyApp\MyApp.exe 名稱 = ENABLE 範圍 = " My Application " 模式 = CUSTOM addresses=157.60.0.1,172.16.0.0/16,LocalSubnet 設定檔 = ALL 請執行下列命令::

netsh advfirewall 防火牆新增規則名稱 = yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet 設定檔允許 program=öC:\MyApp\MyApp.exeö 啟用 = = 在動作 = öMy Applicationö dir = 網域

netsh advfirewall 防火牆新增規則名稱 = yes remoteip=157.60.0.1,172.16.0.0/16,LocalSubnet 設定檔允許 program=öC:\MyApp\MyApp.exeö 啟用 = = 在動作 = öMy Applicationö dir = 私密
如需更多資訊有關如何新增防火牆規則, 請執行下列命令:
netsh 防火牆 advfirewall 新增規則嗎 ?

回此頁最上方

範例 2: 啟用連接埠

舊的指令 新命令
netsh 防火牆將 TCP 連接埠 80 ôOpen 80ö portopening netsh advfirewall 防火牆新增規則名稱 = TCP localport 允許通訊協定 = = 在動作 = 80ö dir öOpen 連接埠 80 =
如需更多資訊有關如何新增防火牆規則, 請執行下列命令:
netsh 防火牆 advfirewall 新增規則嗎 ?

回此頁最上方

範例 3: [ 刪除 ] 啟用程式或連接埠

舊的指令 新命令
C:\MyApp\MyApp.exe netsh 防火牆刪除 allowedprogram 規則名稱 program=öC:\MyApp\MyApp.exeö = advfirewall netsh firewall 刪除規則名稱
刪除通訊協定 portopening = UDP 連接埠 = 500 advfirewall netsh firewall 刪除規則名稱 = 通訊協定 規則名稱 = udp localport = 500
如需如何刪除防火牆規則, 執行下列命令:
netsh advfirewall 防火牆刪除規則嗎 ?

回此頁最上方

範例 4: 設定 ICMP 設定值

舊的指令 新命令
netsh firewall set icmpsetting 8 netsh advfirewall 防火牆新增規則名稱 = = 在動作 = icmpv4:8, 任何 dir = requestö öICMP 回應 V 4 傳入的允許通訊協定允許
netsh firewall set icmpsetting 類型 = ALL 模式 = 啟用 netsh advfirewall 新增規則名稱 = = 在動作任何, 任何 dir: = icmpv4 = öAll V4ö ICMP 通訊協定允許
如需更多資訊 about how to configure ICMP 設定值, 請執行下列命令:
netsh 防火牆 advfirewall 新增規則嗎 ?

回此頁最上方

範例 5: 設定記錄

舊的指令 新命令
netsh firewall set %systemroot%\system32\LogFiles\Firewall\pfirewall.log 4096 ENABLE 啟用記錄 請執行下列命令::

設定記錄檔名 %systemroot%\system32\LogFiles\Firewall\pfirewall.log currentprofile netsh advfirewall

netsh advfirewall currentprofile 4096 maxfilesize 記錄設定
netsh advfirewall 集 currentprofile 記錄 droppedconnections 啟用

netsh advfirewall 集 currentprofile 記錄 allowedconnections 啟用
如需更多資訊, 請執行下列命令:
netsh advfirewall 設定 currentprofile 嗎 ?
如果您要設定為特定的設定檔, 記錄而非 「 currentprofile " 選項使用的下列選項之一:
Domainprofile
Privateprofile
Publicprofile

回此頁最上方

範例 6: 啟用 Windows 防火牆

舊的指令 新命令
netsh firewall set opmode ENABLE 在 netsh advfirewall currentprofile 狀態設定
netsh firewall set opmode 模式 = ENABLE 例外狀況 = 啟用 請執行下列命令::

在設定 Nesth advfirewall currentprofile 狀態

netsh advfirewall 設定 currentprofile firewallpolicy blockinboundalways, allowoutbound
netsh firewall set opmode 模式 = 啟用例外狀況 = 停用設定檔 = domain 請執行下列命令::

在設定 Nesth advfirewall domainprofile 狀態

netsh advfirewall 設定 domainprofile firewallpolicy blockinbound, allowoutbound
netsh firewall set opmode 模式 = ALL = 啟用設定檔 請執行下列命令::

在 netsh advfirewall domainprofile 狀態設定

在 netsh advfirewall privateprofile 狀態設定
如需更多資訊, 請執行下列命令:
netsh advfirewall 設定 currentprofile 嗎 ?
如果您要設定其特定設定檔, 防火牆狀態而非 「 currentprofile " 選項使用的下列選項之一:
Domainprofile
Privateprofile
Publicprofile

回此頁最上方

還原預設原則 7 範例:

舊的指令 新命令
netsh 防火牆重設 netsh advfirewall 重設
如需更多資訊, 請執行下列命令:
netsh advfirewall 重設嗎 ?

回此頁最上方

啟用特定服務範例 8:

舊的指令 新命令
netsh firewall set FileAndPrint 服務 = öFile 和印表機 Sharingö 新啟用 = Yes advfirewall netsh firewall set 規則群組
netsh firewall set RemoteDesktop 啟用服務 = 「 遠端桌面 」 新啟用 = Yes advfirewall netsh firewall set 規則群組
netsh firewall set RemoteDesktop 服務設定檔啟用 = ALL 請執行下列命令::

advfirewall netsh firewall set 規則群組 = 「 遠端桌面 」 新啟用 = [ 是 ] 設定檔 = domain

advfirewall netsh firewall set 規則群組 = 「 遠端桌面 」 新啟用 = [ 是 ] 設定檔 = 私密

回此頁最上方


這篇文章中的資訊適用於:
Windows Server 2008 Enterprise
Windows Server 2008 Datacenter
Windows Server 2008 Standard
Windows Server 2008 for Itanium-Based Systems
Windows Vista Ultimate
Windows Vista Ultimate 64-bit Edition
Windows Vista Enterprise
Windows Vista Enterprise 64-bit Edition
Windows Vista Business
Windows Vista Business 64-bit Edition
Windows Vista Home Premium
Windows Vista Home Premium 64-bit Edition
Windows Vista Home Basic
Windows Vista Home Basic 64-bit Edition