NETSH - CMD


Overview

netsh (Network Shell) is a command-line scripting utility that allows you to, either locally or remotely, display or modify the network configuration of a computer that is currently running. It provides an extensive set of subcommands for managing network components such as the Windows Firewall, network policies, and many other network functions. It is particularly useful for network administrators in configuring network interfaces, or in scripts to automate networking tasks.

Syntax

The basic syntax for netsh is as follows:

netsh [Context] [SubContext] command [parameter1 = value1 [parameter2 = value2 [...]]]

Where:

  • Context is the environment that netsh operates on, such as wlan for wireless networks or firewall for Windows Firewall settings.
  • SubContext specifies a more detailed area within the context.
  • command is the action to be performed.
  • parameters specify the command-specific arguments.

Common Contexts

  • wlan: Configure Wireless LAN settings.
  • lan: Configure Wired LAN settings.
  • firewall: Manage Windows Firewall settings.

Options/Flags

Options vary by the context and command used in netsh. Below are some general flags:

  • -a Alias: Runs in alias mode.
  • -r RemoteMachine: Specifies that the operation is to be performed on a remote machine.
  • -u [Domain]User: Specifies the user context under which the command should run.
  • -p Password: Specifies the password for the given user context.

Examples

1. Display all wireless networks visible to the system

netsh wlan show networks

2. Connect to a specific wireless network

netsh wlan connect name="NetworkName"

3. Add a new IP address to a specified interface

netsh interface ip add address "Local Area Connection" 192.168.0.2 255.255.255.0

4. Reset the network adapter

netsh int ip reset c:\resetlog.txt

Common Issues

  • Permissions: Many netsh commands require administrative privileges. Running them without sufficient rights produces errors.
  • Syntax Errors: Due to the complexity and variety of the netsh contexts and commands, syntax errors are common. Double-checking command syntax against official Microsoft documentation can help.

Integration

netsh can be combined with batch scripting or PowerShell to automate networking tasks. For example:

FOR /F "tokens=*" %i IN ('netsh wlan show networks ^| findstr "SSID"') DO @echo Found network: %i

This script scans for available Wi-Fi networks and prints each SSID found.

  • ipconfig: Displays all current TCP/IP network configuration values.
  • ping: Checks connectivity with another network host.
  • tracert: Traces the path taken to a network host.

For more information, the official Microsoft documentation on netsh provides a comprehensive resource: Netsh Technical Overview.

These sections collectively provide a robust manual to effectively employ and troubleshoot the netsh command, adapting it to various network management and configuration needs.