Condividi tramite


Netsh Overview

Applies To: Windows Server 2008

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 commands can be run by typing commands at the netsh prompt and they can be used in batch files or scripts. Remote computers and the local computer can be configured by using netsh commands.

Netsh also provides a scripting feature that allows you to run a group of commands in batch mode against a specified computer. With netsh, you can save a configuration script in a text file for archival purposes or to help you configure other computers.

Netsh contexts

Netsh interacts with other operating system components by using dynamic-link library (DLL) files. Each netsh helper DLL provides an extensive set of features called a context, which is a group of commands specific to a networking component. These contexts extend the functionality of netsh by providing configuration and monitoring support for one or more services, utilities, or protocols. For example, Dhcpmon.dll provides netsh with the context and set of commands necessary to configure and manage DHCP servers.

Running netsh commands

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. For example, if you type dhcp at the netsh prompt and press ENTER, netsh changes to the DHCP server context. If you do not have DHCP installed, however, the following message appears:

The following command was not found: dhcp.

Available contexts

For more information about Netsh contexts, see the following topics:

Subcontexts

Netsh contexts can contain both commands and additional contexts, called subcontexts. For example, within the Routing context, you can change to the IP and IPv6 subcontexts.

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. 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

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. 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:

routing ip igmp add interface "Local Area Connection" startupqueryinterval=21

Running Netsh commands from command prompt

To start Network Shell and enter netsh at the command prompt, follow the command below.

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. Used without parameters, netsh opens the Netsh.exe command prompt (that is, netsh>).

Syntax

netsh[ -aAliasFile] [ -cContext ] [-rRemoteComputer] [ -u [ DomainName\ ] UserName ] [ -pPassword | *] [{NetshCommand | -fScriptFile}]

Parameters

  • -a
    Optional. Specifies that you are returned to the netsh prompt after running AliasFile.
  • AliasFile
    Optional. Specifies the name of the text file that contains one or more netsh commands.
  • -c
    Optional. Specifies that netsh enters the specified netsh context.
  • Context
    Optional. Specifies the netsh context that you want to enter. For more information, see Enter a Netsh Context.
  • -r
    Optional. Specifies that you want the command to run on a remote computer.

Important

To use some netsh commands, such as the netsh firewall commands, remotely on another computer by using the netsh –r parameter, the Remote Registry service must be running on the remote computer. If it is not, then Windows displays a “Network Path Not Found” error message.

  • RemoteComputer
    Optional. Specifies the remote computer that you want to configure.
  • -u
    Optional. Specifies that you want to run the netsh command under a user account.
  • DomainName\
    Optional. Specifies the domain where the user account is located. The default is the local domain if DomainName\ is not specified.
  • UserName
    Optional. Specifies the user account name.
  • -p
    Optional. Specifies that you want to provide a password for the user account.
  • Password
    Optional. Specifies the password for the user account that you specified with -uUserName.
  • NetshCommand
    Optional. Specifies the netsh command that you want to run.
  • -f
    Optional. Exits netsh after running the script that you designate with ScriptFile.
  • ScriptFile
    Optional. Specifies the script that you want to run.
  • /?
    Optional. Displays help at the netsh prompt.

Remarks

  • 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. If you specify -r without another command, netsh opens in remote mode. The process is similar to using set machine at the Netsh command prompt. When you use -r, you set the target computer for the current instance of netsh only. After you exit and reenter netsh, the target computer is reset as the local computer. 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.

Typing parameter string values for netsh commands

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"

For information on how to interpret netsh command syntax, see Formatting Legend.