Using Netsh to Configure and Monitor Computers


The Netsh tool provides a command-line, scripting interface for configuring and monitoring computers running Windows XP Professional. By using the Netsh tool, you can issue context commands to the appropriate helper, and the helper then carries out the command. A helper is a dynamic-link library (DLL) file that extends the functionality of the Netsh tool by providing configuration, monitoring, and support for one or more services, tools, or protocols. The helper can also be used to extend other helpers.

Context commands are groupings of Netsh commands for specific networking components. A specific context is identified by a string that is appended to commands. Commands entered in a specific context are passed to an associated helper. The contexts available depend on the Windows XP Professional components installed. For example, type routing at the netsh prompt to change to the routing context.

You can use commands in the Netsh Interface IP context to configure the TCP/IP protocol (including addresses, default gateways, DNS servers, and WINS servers) and to display configuration and statistical information.

You can run these commands from the Windows XP command prompt or from the command prompt for the Netsh Interface IP context. For these commands to work at the Windows XP command prompt, you must type Netsh interface ip before typing commands and parameters as they appear in the syntax below. To run these Netsh commands on a remote Windows 2000 Server, you must first use Remote Desktop Connection to connect to a Windows 2000 Server that is running Terminal Server. There might be functional differences between Netsh context commands on Windows 2000 and Windows XP.

As an example of how to use Netsh to configure an interface, the following command configures the interface named Local Area Connection with the static IP address 10.0.5.99, the subnet mask of 255.255.255.0, and a default gateway of 10.0.5.1:

set address name="Local Area Connection" source=static addr=10.0.5.99 mask=255.255.255.0 gateway=10.0.5.1

Netsh command-line options include the following:

  • -a AliasFile

    Specifies that an alias file is used. An alias file contains a list of netsh commands and an aliased version so that you can use the aliased command line in place of the netsh command. You can use alias files to map commands that are more familiar in other platforms to the appropriate netsh command.

  • -c Context

    Specifies the context of the command that corresponds to an installed helper DLL.

  • Command

    Specifies the netsh command to carry out.

  • -f ScriptFile

    Specifies that all of the netsh commands in the ScriptFile file are executed.

  • -r RemoteMachine

    Specifies that the netsh commands are carried out on a remote computer specified by either its name or IP address.

You can abbreviate commands to the shortest unambiguous string. For example, issuing the command sh ip int is equivalent to issuing show ip interface. Netsh commands can be either global or context-specific. Global commands can be issued in any context and are used for general Netsh tool functions. Context-specific commands vary according to the context. You can log commands issued to a log file to create an audit trail of a netsh command session.

Table 21-2 lists the netsh global commands.

Table 21-2: Netsh commands and descriptions

Command

Description

..

Moves up one context level

? or help

Displays command-line Help

show version

Displays the current version of Windows and the Netsh tool

show netdlls

Displays the current version of installed Netsh helper DLLs

add helper

Add a Netsh help DLL

delete helper

Removes a Netsh help DLL

show helper

Displays the installed Netsh helper DLLs

cmd

Opens a command window

online

Sets the current mode to online

offline

Sets the current mode to offline

set mode

Sets the current mode to online or offline

show mode

Displays the current mode

flush

Discards any changes in offline mode

commit

Commits changes made in offline mode

set audit-logging

Turns on or turns off the logging facility

show audit-logging

Displays current audit logging settings

set loglevel

Sets level of logging information

show loglevel

Displays the level of logging information

set machine

Configures the computer on which the netsh commands are executed

show machine

Displays the computer on which the netsh commands are executed

exec

Executes a script file containing netsh commands

quit or bye or exit

Exits the Netsh tool

add alias

Adds an alias to an existing command

delete alias

Deletes an alias from an existing command

show alias

Displays all defined aliases

dump

Writes configuration to a text file

popd

A scripting command that pops a context from the stack

pushd

A scripting command that pushes the current context on the stack

The Netsh tool has the following command modes:

  • Online. In online mode, commands issued at a Netsh command prompt are executed immediately.

  • Offline. In offline mode, commands issued at a Netsh command prompt are accumulated and carried out as a batch by issuing the commit global command. You can discard accumulated commands by issuing the flush global command.

  • Script. By using either the -f command-line option or by issuing the exec global command at a Netsh command prompt, all the netsh commands in the specified file are executed.




Microsoft Windows XP Professional Resource Kit 2003
Microsoft Windows XP Professional Resource Kit 2003
ISBN: N/A
EAN: N/A
Year: 2005
Pages: 338
BUY ON AMAZON

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net