,

Netsh Networking Shell Tutorial

In this Netsh Networking Shell Tutorial, I explain how to use the Netsh command line scripting utility that has been around since Windows Server 2003. Although somewhat depreciated by cmdlets available in PowerShell, Netsh can allow you to view or change the network configuration of your local computer or a remote computer. The tutorial takes you through how to browse around the tool, open contexts, and use sub-contexts to navigate through commands. It also covers how to use Netsh to manage remote servers and workstations, popular Netsh commands, and even provides an example batch file. The reason I created this tutorial was to help me improve my understanding of Netsh before my then-upcoming Microsoft interview to be a Senior Solutions Architect.

Netsh Overview

Netsh, pronounced just as it’s spelt as “netch”, is a command line scripting utility that’s been around since Windows Server 2003. Although somewhat depreciated by cmdlets available in PowerShell, Netsh can allow you to view or change the network configuration of your local computer or a remote computer. Netsh can be run at the command line or built into a script inside of a batch file.

To start Netsh, open a command line shell or PowerShell and type:


Netsh

How to Browse Netsh

Once inside Netsh, type “?” to see a list of commands available to you:

Note how it describes the list as “commands in this context”. Contexts are groups of commands available to you once you are inside of their context. Contexts can be nested in other Contexts and you’ll see it lists what sub-contexts are available. To get inside a context, just type its name, such as interface, and again a “?” will show you what commands area available to you in that context.

This is generally how you browse around. By opening contexts, typing “?” to see what is available, and typing sub-contexts to get even deeper until you find the command you want.

Also, note how it mentions that PowerShell should be used rather than Netsh for TCP/IP commands. This is true for most Netsh commands, so just keep in mind that, although useful, PowerShell has largely taken over Netsh.

Using Netsh to Manage Remote Servers and Workstations

While you’re still at the cmd line shell (net yet into Netsh), you can invoke Netsh against a remote computer by following this format:


Netsh -r  -u <domain\user> -p  

In this example, we can see the IPV4 information on the remote computer 63769:

For the -r argument, you can supply the hostname as either the IP address, the hostname, or the FQDN of the remote host.

Running Commands in Netsh

The general syntax to run a netsh command is:


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

For example, to open a firewall port on a remote computer:


netsh –r WORKSTATION001 –u DOMAIN\User –P P@ssw0rd! advfirewall set portopening tcp 445 smb enable

Additionally, some commands require a parameter string. In the case where the parameter string requires a space, be sure to include it in quotes:


interface="Wireless Network Connection"

Popular Netsh Commands

  1. Show the IP configuration
    
    netsh interface ip show config
    
  2. Show IPv4 or IPv6 information
    
    netsh interface ipv6 show address
    
  3. Open a Firewall Port
    
    netsh advfirewall firewall
      add rule name="HTTPS"
      dir=in action=allow protocol=TCP localport=443
    
  4. Show Network Adapter Status
    
    netsh interface show interface
    
  5. Configure adapter for static IP Address
    
    netsh interface ip
      set address "Local Area Connection"
      static 192.168.0.100
      255.255.255.0 192.168.0.254 1
    
  6. Configure adapter to use DHCP
    
    netsh interface ip 
      set dns "Local Area Connection" dhcp
    

Example Batch File

This is an example batch file:


netsh wins server 192.168.125.30 add name Name=MY\_RECORD EndChar=04 IP={192.168.0.205}

netsh wins server 192.168.125.30 add partner Server=192.168.0.189 Type=2
  
netsh wins server 192.168.0.189 add partner Server=192.168.125.30 Type=2
  
netsh wins server 192.168.125.30 init push Server=192.168.0.189 PropReq=0
  
netsh wins server 192.168.0.189 show name Name=MY\_RECORD EndChar=04
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *