Microsoft

Get IT Done: Use Win2K's NETSH to manage networking

Configure many areas of Win2K-based networking with NETSH


Windows 2000’s NETSH utility is an advanced administration tool that provides information and configuration options for your Windows 2000 networks and clients. NETSH offers many ways of monitoring, configuring, exporting, and importing your network information. In this article, I will show you what NETSH can do. I've also put together a downloadable NETSH reference sheet to help you take advantage of this tool.

A powerful configuration tool
I stumbled across NETSH while trying to solve problems my laptop had making various office, home, dial-up, and client network connections. I used NETSH to make a configuration file of each LAN that can be imported as needed, and my networking issues (mainly name resolution, Web surfing, and DHCP lease issues) disappeared.

NETSH was introduced with Windows 2000 and is part of the default installation for all versions of Win2K. It allows administrators to configure many areas of Win2K-based networking. NETSH interacts with different contexts related to Windows networking. (Context, in this case, refers to a logical category of networking, such as DHCP and WINS.)

A context interacts directly with a Dynamic Link Library (.dll) related to that particular dimension of Windows networking. Within contexts are subcontexts that monitor and configure networking subtopics. NETSH can also run across the network to other Windows 2000 computers when applicable permissions or domain trusts exist. The NETSH tool is a powerful configuration tool that can give an administrator more options in managing Win2K.

Using NETSH
By default, the NETSH executable (Netsh.exe) is located in C:\WINNT\SYSTEM32\. You can access it simply by typing netsh from a command prompt. This will bring you into the tool in the interactive mode (described later), changing the prompt to netsh>. You can also perform NETSH functions from outside of the netsh> prompt (command mode).

When using NETSH, typing ? or help will show you the available options based on your context. Entering a partial command followed by ? will show you the options available for completing the command you are attempting to execute. If you ever mistype a command or provide bogus parameters, NETSH will present the available commands for your current context, just as if you'd typed ?.

To get into a context in NETSH, type the name of that context from the netsh> prompt. For example, typing interface will jump immediately to the network interface context. Once you are in a context, typing help or ? will display the available subcontexts. In the interface context, for example, ip is one of the subcontexts. The show command will display information about the current context or subcontext. The set command will allow you to interact with the networking components and make changes to the network configuration.

As you can see, navigating through the contexts in NETSH is important. To move up the context tree one level, simply type “..”. If you're a beginner, navigating into the different contexts and running their context help is the easiest way to get familiar with different areas of NETSH.

NETSH contexts
NETSH offers the following top-level contexts for configuring the Windows networking components:
  • AAAA is available only in Windows 2000 Server editions and configures the AAAA component used by Routing and Remote Access and Internet Authentication Services.
  • DHCP is available only in Windows 2000 Server editions and configures the DHCP service options (if installed).
  • WINS is available only in Windows 2000 Server editions and configures the WINS service options (if installed).
  • Interface is available in all Windows 2000 versions and configures the network setup of all network interfaces.
  • RAS is available in all Windows 2000 versions and configures the RAS dial-in for the computer.
  • Routing is available in all Windows 2000 versions and configures any protocol routing performed by the computer.

Online and offline modes
NETSH makes good use of online and offline modes. Online mode is a live configuration interface, where changes are reflected immediately. Offline mode allows you to make your desired changes and review them by switching to online mode. Figure A shows how to start a session, go into offline mode, make a change, and switch into online mode.

Figure A


It is a good practice to go into offline mode as part of your NETSH routine if you are making changes on the fly in the interactive shell. It is also helpful to use offline mode if you are importing configurations because you'll have the opportunity to ensure that your settings are properly executed before making them live.

Exporting and importing configurations
The feature that brought me to NETSH was its ability to store and retrieve network configurations for my laptop. I had connected to numerous networks and was tired of manually making the appropriate changes for each location I visited intermittently. NETSH allows you to export a script file that can be retrieved later when you want to reinstate this configuration. You can even make the file into a Windows shortcut and reimport it without going into the command prompt.

NETSH can import or export any context. The following example will illustrate a step-by-step export and reimport of the interface context for my laptop.

Exporting the interface context to a file
Start by accessing a command prompt and typing the following command:
netsh -c interface dump >  c:\scripts\office_lan.netsh

Let’s analyze this command:
netsh (run NETSH in command mode)
–c (specify a context)
interface (specify which context)
dump (specify what to do with the context)
>  (dump the context to a file; without this section, it will dump to the screen)
c:\netsh_scripts\office_lan.netsh (specify the path of the file to be exported)


When exporting a file, I arbitrarily chose a .netsh file extension. The file is a text document that opens and edits fine in any text editor. The .netsh extension makes it easy to remember what the file is if you see it sitting around later, but any extension will do. Also, when the command is run, the path must already exist. In other words, running NETSH in command mode won't create directories/folders.

The exported file is simple looking, but more complex configurations can arise in different contexts. Figure B shows the exported file from the example command I executed on my computer.

Figure B


Importing the interface context from a file
Retrieving a NETSH configuration is easy. The command below illustrates how to retrieve the configuration outlined in the previous example:
netsh -f c:\scripts\office_lan.netsh

This command runs NETSH with the –f parameter, which denotes a script file to be imported. The script file is then specified. Once the command is executed from the command line, the changes are brought into the Windows networking configuration. If a reboot would be necessary if these changes were made in the Windows GUI, NETSH will not prompt you.

A popular way of using the NETSH import and export functionality is in a networked environment consisting of a large number of computers with static IP addresses. Using similar network environments and other tools to make sure that what you are importing will accurately make the changes you are after (via testing), you can make network changes or large rollouts in a more controlled and time-efficient manner. NETSH's RemoteMachine option allows configurations to be executed across the network when account credentials or a domain trust exists.

Navigation and modes
NETSH has two modes: command and interactive. Command mode is a task that runs from the C:\> prompt; interactive mode runs from within the netsh> prompt. Exporting a network configuration to a file is an example of running in command mode. Running NETSH and entering commands one at a time is an example of interactive mode, which gives you access to navigate among NETSH contexts.

Command mode is limited, since it's optimized for configurations you are ready to invoke. Working in command mode, you might dump and retrieve a network configuration. Interactive mode is more user-friendly because you have better access to help files and can work with different contexts and subcontexts in more detail. Changing to and from online and offline modes are examples of interactive commands.

What about NT?
Although NETSH was introduced with Windows 2000, and XP includes it as well, it can gather limited information from Windows NT computers over the network. For connecting to remote computers, there must be a domain trust or account privileges to allow the information to go from the remote resource to your Windows 2000 computer running NETSH.

NETSH itself does not let you specify account credentials when connecting to a computer (unlike NET USE). For example, on a Windows 2000 computer in a mixed domain or with similar credentials, I can get WINS information over the network from a WINS server on a Windows NT computer. The full, robust NETSH information can't be implemented on Windows NT, but running NETSH over the network to a Windows NT server can provide you with limited information on network services.

Administrative benefits
NETSH can be helpful for the administrator managing multiple network configurations. Depending on what context you choose to explore and use, it can streamline your administrative responsibilities and allow for greater control in managing a Windows 2000 network.

Have a comment or a question?
We look forward to getting your input and hearing about your experiences regarding this topic. Post a comment or a question about this article.

 

About Rick Vanover

Rick Vanover is a software strategy specialist for Veeam Software, based in Columbus, Ohio. Rick has years of IT experience and focuses on virtualization, Windows-based server administration, and system hardware.

Editor's Picks