Netsh 命令語法、內容,以及格式Netsh Command Syntax, Contexts, and Formatting

適用於:Windows Server(以每年次管道)、Windows Server 2016Applies To: Windows Server (Semi-Annual Channel), Windows Server 2016

若要了解如何輸入 netsh 內容和子,了解 netsh 語法和命令格式,以及如何執行 netsh 命令本機和遠端電腦上,您可以使用此主題。You can use this topic to learn how to enter netsh contexts and subcontexts, understand netsh syntax and command formatting, and how to run netsh commands on local and remote computers.

Netsh 是電腦的一個命令列指令碼的公用程式,可讓您顯示或修改網路設定目前執行的是電腦的。Netsh is a command-line scripting utility that allows you to display or modify the network configuration of a computer that is currently running. Netsh 命令可以 netsh 命令提示字元中,輸入命令執行,並在「批次檔案或指令碼所使用。Netsh commands can be run by typing commands at the netsh prompt and they can be used in batch files or scripts. 使用 netsh 命令可以設定遠端電腦與本機電腦。Remote computers and the local computer can be configured by using netsh commands.

Netsh 指令碼,可讓您在「批次模式之電腦執行的命令。Netsh also provides a scripting feature that allows you to run a group of commands in batch mode against a specified computer. 使用 netsh,您可以在文字檔案保存用途,或為協助您設定的其他電腦中儲存設定指令碼。With netsh, you can save a configuration script in a text file for archival purposes or to help you configure other computers.

Netsh 內容Netsh contexts

Netsh 與其他作業系統元件使用 dynamic\ 連結庫 (DLL) 檔案。Netsh interacts with other operating system components by using dynamic-link library (DLL) files.

每個 netsh 授與協助者 DLL 提供一組擴充功能稱為操作,這是一組命令特定網路伺服器角色或功能。Each netsh helper DLL provides an extensive set of features called a context, which is a group of commands specific to a networking server role or feature. 這些內容擴充功能的 netsh 提供設定及監視一或多個服務、公用程式或通訊協定的支援。These contexts extend the functionality of netsh by providing configuration and monitoring support for one or more services, utilities, or protocols. 例如,Dhcpmon.dll 提供 netsh 操作與設定的設定及管理 DHCP 伺服器所需的命令。For example, Dhcpmon.dll provides netsh with the context and set of commands necessary to configure and manage DHCP servers.

取得內容清單Obtain a list of contexts

您可以取得 netsh 內容清單打開 Windows PowerShell 或命令提示字元中執行 Windows Server 2016 或 Windows 10 電腦上。You can obtain a list of netsh contexts by opening either command prompt or Windows PowerShell on a computer running Windows Server 2016 or Windows 10. 輸入命令netsh按下 ENTER。Type the command netsh and press ENTER. 輸入日嗎?,然後按 ENTER 鍵。Type /?, and then press ENTER.

以下是這些命令執行 Windows Server 2016 Datacenter 的電腦上的範例輸出。Following is example output for these commands on a computer running Windows Server 2016 Datacenter.

PS C:\Windows\system32> netsh
netsh>/?

The following commands are available:

Commands in this context:
..            - Goes up one context level.
?             - Displays a list of commands.
abort         - Discards changes made while in offline mode.
add           - Adds a configuration entry to a list of entries.
advfirewall   - Changes to the `netsh advfirewall' context.
alias         - Adds an alias.
branchcache   - Changes to the `netsh branchcache' context.
bridge        - Changes to the `netsh bridge' context.
bye           - Exits the program.
commit        - Commits changes made while in offline mode.
delete        - Deletes a configuration entry from a list of entries.
dhcpclient    - Changes to the `netsh dhcpclient' context.
dnsclient     - Changes to the `netsh dnsclient' context.
dump          - Displays a configuration script.
exec          - Runs a script file.
exit          - Exits the program.
firewall      - Changes to the `netsh firewall' context.
help          - Displays a list of commands.
http          - Changes to the `netsh http' context.
interface     - Changes to the `netsh interface' context.
ipsec         - Changes to the `netsh ipsec' context.
ipsecdosprotection - Changes to the `netsh ipsecdosprotection' context.
lan           - Changes to the `netsh lan' context.
namespace     - Changes to the `netsh namespace' context.
netio         - Changes to the `netsh netio' context.
offline       - Sets the current mode to offline.
online        - Sets the current mode to online.
popd          - Pops a context from the stack.
pushd         - Pushes current context on stack.
quit          - Exits the program.
ras           - Changes to the `netsh ras' context.
rpc           - Changes to the `netsh rpc' context.
set           - Updates configuration settings.
show          - Displays information.
trace         - Changes to the `netsh trace' context.
unalias       - Deletes an alias.
wfp           - Changes to the `netsh wfp' context.
winhttp       - Changes to the `netsh winhttp' context.
winsock       - Changes to the `netsh winsock' context.

The following sub-contexts are available:
 advfirewall branchcache bridge dhcpclient dnsclient firewall http interface ipsec ipsecdosprotection lan namespace netio ras rpc trace wfp winhttp winsock

To view help for a command, type the command, followed by a space, and then
 type ?.

Subcontexts

Netsh 內容可以包含命令和其他內容,稱為Netsh contexts can contain both commands and additional contexts, called subcontexts. 例如中路由,您可以變更 IP 和 IPv6 子。For example, within the Routing context, you can change to the IP and IPv6 subcontexts.

顯示命令清單,您可以使用 netsh 命令提示字元中,於操作,在子輸入操作名稱,然後鍵入任一個日嗎?To display a list of commands and subcontexts that you can use within a context, at the netsh prompt, type the context name, and then type either /? 協助or help. 例如,若要路由操作,在 netsh 提示中顯示的子,您可以使用的命令清單 \ (也就是netsh>),輸入下列其中一個動作:For example, to display a list of subcontexts and commands that you can use in the Routing context, at the netsh prompt (that is, netsh>), type one of the following:

路由日嗎?routing /?

尚協助routing help

另一個操作中執行工作,而無須更動您目前操作從,輸入您想要使用 netsh 命令提示字元中的命令操作路徑。To perform tasks in another context without changing from your current context, type the context path of the command you want to use at the netsh prompt. 例如,若要新增介面「本機區域連接」中 IGMP 操作而不會先變更 netsh 命令提示字元中,於 IGMP 操作,以輸入:For example, to add an interface named "Local Area Connection" in the IGMP context without first changing to the IGMP context, at the netsh prompt, type:

路由 ip igmp 新增介面「本機區域連接」startupqueryinterval = 21routing ip igmp add interface "Local Area Connection" startupqueryinterval=21

Netsh 命令的執行Running netsh commands

若要執行 netsh 命令,必須開始 netsh 命令提示字元中輸入netsh,然後按 ENTER 鍵。To run a netsh command, you must start netsh from the command prompt by typing netsh and then pressing ENTER. 接下來,您可以變更操作包含您想要使用的命令。Next, you can change to the context that contains the command you want to use. 您已安裝的網路元件可內容而定。The contexts that are available depend on the networking components that you have installed. 例如,如果您輸入dhcp在 netsh 命令提示字元中,按下 ENTER netsh 變更 DHCP 伺服器操作。For example, if you type dhcp at the netsh prompt and press ENTER, netsh changes to the DHCP server context. 如果您不需要安裝 DHCP,不過,會顯示以下訊息:If you do not have DHCP installed, however, the following message appears:

找不到下列命令:dhcp。The following command was not found: dhcp.

格式設定的圖例Formatting Legend

您可以使用下列格式圖例上尚未取得共識,並使用正確 netsh 命令語法 netsh 命令提示字元中,或在「批次檔案或指令碼執行的命令。You can use the following formatting legend to interpret and use correct netsh command syntax when you run the command at the netsh prompt or in a batch file or script.

  • 中的文字斜體是您輸入命令時,您必須提供的資訊。Text in Italic is information that you must supply while you type the command. 例如,如果命令有一個名為-參數的使用者名稱,您必須輸入實際的使用者名稱。For example, if a command has a parameter named -UserName, you must type the actual user name.
  • 中的文字粗體會完全如您輸入命令時,您必須輸入的資訊。Text in Bold is information that you must type exactly as shown while you type the command.
  • 文字後面省略符號 (...) 是參數,可在命令列重複數次。Text followed by an ellipsis (...) is a parameter that can be repeated several times in a command line.
  • 文字括弧之間的 [ ] 是選擇性的項目。Text that is between brackets [ ] is an optional item.
  • 大括弧之間的文字 { } 的選項,以管道提供一組選擇,您必須選取只有一個,例如{enable|disable}Text that is between braces { } with choices separated by a pipe provides a set of choices from which you must select only one, such as {enable|disable}.
  • Courier 字型格式化的文字是代碼或程式輸出。Text that is formatted with the Courier font is code or program output.

從 Windows PowerShell 或命令提示字元中執行 Netsh 命令Running Netsh commands from the command prompt or Windows PowerShell

[開始] 的網路殼層,並輸入 netsh Windows PowerShell 或命令提示字元中,您可以使用下列命令。To start Network Shell and enter netsh at the command prompt or in Windows PowerShell, you can use the following command.

netshnetsh

Netsh 是一個命令列指令碼的公用程式,可讓您在本機或遠端電腦上,顯示器或修改電腦目前執行的網路設定。Netsh is a command-line scripting utility that allows you to, either locally or remotely, display or modify the network configuration of a currently running computer. 通常,若不使用netsh開啟 Netsh.exe 命令提示字元 \ (也就是netsh>)。Used without parameters, netsh opens the Netsh.exe command prompt (that is, netsh>).

語法Syntax

netsh[ -a AliasFile] [ -c Context ] [-r RemoteComputer] [ -u [ DomainName\ ] UserName ] [ -p Password | *] [{NetshCommand | -f ScriptFile}]netsh[ -a AliasFile] [ -c Context ] [-r RemoteComputer] [ -u [ DomainName\ ] UserName ] [ -p Password | *] [{NetshCommand | -f ScriptFile}]

參數Parameters

-a

選用。Optional. 指定您會回到netsh之後執行提示AliasFileSpecifies that you are returned to the netsh prompt after running AliasFile.

AliasFile

選用。Optional. 指定名稱包含下列一或多個文字檔案的netsh的命令。Specifies the name of the text file that contains one or more netsh commands.

-c

選用。Optional. 指定指定該 netsh,輸入netsh操作。Specifies that netsh enters the specified netsh context.

Context

選用。Optional. 指定netsh,輸入您想要的操作。Specifies the netsh context that you want to enter.

-r

選用。Optional. 指定您想要在遠端電腦上執行的命令。Specifies that you want the command to run on a remote computer.

重要

當您使用一些 netsh 命令從遠端使用另一部電腦上netsh – r參數,必須在遠端電腦上執行遠端登錄服務。When you use some netsh commands remotely on another computer with the netsh –r parameter, the Remote Registry service must be running on the remote computer. 如果這不執行,Windows 就會顯示「網路路徑找不到「的錯誤訊息。If it is not running, Windows displays a “Network Path Not Found” error message.

RemoteComputer

選用。Optional. 指定您想要設定遠端電腦。Specifies the remote computer that you want to configure.

-u

選用。Optional. 指定您要在帳號 netsh 命令的執行。Specifies that you want to run the netsh command under a user account.

DomainName\\

選用。Optional. 指定帳號所在位置的網域。Specifies the domain where the user account is located. 預設值是本機的網域如果DomainName\未指定。The default is the local domain if DomainName\ is not specified.

UserName

選用。Optional. 指定的使用者 account 名稱。Specifies the user account name.

-p

選用。Optional. 指定您要帳號提供的密碼。Specifies that you want to provide a password for the user account.

Password

選用。Optional. 指定您與指定的使用者 account 密碼-u的使用者名稱Specifies the password for the user account that you specified with -u UserName.

NetshCommand

選用。Optional. 指定netsh您想要執行的命令。Specifies the netsh command that you want to run.

-f

選用。Optional. 結束netsh之後您與指定的指令碼執行的指令碼檔案Exits netsh after running the script that you designate with ScriptFile.

ScriptFile

選用。Optional. 指定您要執行的指令碼。Specifies the script that you want to run.

/?

選用。Optional. 顯示協助在 netsh 提示。Displays help at the netsh prompt.

注意

若您指定-r後面另一個命令,netsh遠端電腦上執行的命令,然後返回 Cmd.exe 命令提示字元。If you specify -r followed by another command, netsh runs the command on the remote computer and then returns to the Cmd.exe command prompt. 若您指定-r另一個命令,而netsh開啟遠端模式。If you specify -r without another command, netsh opens in remote mode. 此程序很類似,使用設定電腦在 Netsh 命令提示字元。The process is similar to using set machine at the Netsh command prompt. 當您使用-r,您可以設定目標電腦目前執行個體的netsh只。When you use -r, you set the target computer for the current instance of netsh only. 在您結束,並重新輸入後netsh的目標電腦重設為 [本機電腦。After you exit and reenter netsh, the target computer is reset as the local computer. 您可以在執行netsh命令所指定電腦遠端電腦上的儲存 wins UNC 名稱、網際網路名稱解析 DNS 伺服器,或 IP 位址的名稱。You can run netsh commands on a remote computer by specifying a computer name stored in WINS, a UNC name, an Internet name to be resolved by the DNS server, or an IP address.

輸入 netsh 命令的參數字串值Typing parameter string values for netsh commands

整個 Netsh 命令參考有命令包含字串值是必要的參數。Throughout the Netsh command reference there are commands that contain parameters for which a string value is required.

在如此字串值,其中包含字元,例如,包含數個文字,字串值之間的空間很需要引號住字串值。In the case where a string value contains spaces between characters, such as string values that consist of more than one word, it is required that you enclose the string value in quotation marks. 例如參數名為介面字串值為無線網路連接,使用引號字串值:For example, for a parameter named interface with a string value of Wireless Network Connection, use quotation marks around the string value:

interface="Wireless Network Connection"