COMMAND

netshNetwork shell for interface, firewall and Wi-Fi

netsh (network shell) configures nearly every part of Windows networking from the command line: interface addresses, Windows Defender Firewall rules, Wi-Fi profiles, the dynamic port range, and stack resets. It is organised into contexts such as interface, advfirewall and wlan, each with its own commands.

BlackhawkHub Editorial · Updated

Purpose

netsh is a single command that reaches deep into Windows networking through a tree of contexts. You either enter a context interactively or give the full path on one line.

Contexts you will actually use

ContextFor
interface ipv4 / ipv6Addresses, DNS, the dynamic port range
advfirewall firewallWindows Defender Firewall rules
wlanWireless profiles and diagnostics
winsockReset the Winsock catalog
int tcpTCP global settings

Set a static IP address

cmd
netsh interface ipv4 set address name="Ethernet" static 192.168.1.50 255.255.255.0 192.168.1.1
netsh interface ipv4 set dns name="Ethernet" static 1.1.1.1
netsh interface ipv4 add dns name="Ethernet" 1.0.0.1 index=2

Return to DHCP:

cmd
netsh interface ipv4 set address name="Ethernet" dhcp
netsh interface ipv4 set dns name="Ethernet" dhcp

See static vs dynamic IP.

Firewall rules

cmd
netsh advfirewall firewall add rule name="Allow RDP from mgmt" dir=in action=allow protocol=TCP localport=3389 remoteip=10.20.0.0/16
netsh advfirewall firewall show rule name=all
netsh advfirewall set allprofiles state on

The firewall basics record explains profiles and scoping; port 3389 covers RDP exposure.

Wi-Fi

cmd
netsh wlan show profiles
netsh wlan show profile name="MyNetwork" key=clear
netsh wlan show interfaces

Reset the stack

cmd
netsh winsock reset
netsh int ip reset

Reboot afterward. This is a standard repair for corrupted network configuration, layered service providers left by removed software, or a machine that shows a valid IP but cannot pass traffic.

The dynamic port range

cmd
netsh int ipv4 show dynamicport tcp
netsh int ipv4 set dynamicport tcp start=10000 num=55000

See ephemeral ports for when to change it.

Common mistakes

  • Not running elevated. Show commands work unprivileged; every change needs administrator rights.
  • Wrong interface name. It must match netsh interface show interface exactly, quotes included.
  • Resetting the stack as a first step. It is disruptive; try ipconfig and driver checks first.

Frequently asked questions

How do I reset the network stack with netsh?

From an elevated prompt: netsh winsock reset and netsh int ip reset, then reboot. This rebuilds the Winsock catalog and TCP/IP settings and fixes many "connected but no internet" problems caused by damaged network software.

How do I see a saved Wi-Fi password?

netsh wlan show profile name="SSID" key=clear shows the key under "Key Content" for networks this machine has connected to, if you have administrator rights.

Is netsh deprecated?

The interface and some contexts are stable, but Microsoft steers new work toward PowerShell NetTCPIP, NetAdapter and NetSecurity modules. netsh remains fully supported and is still the quickest way to do several tasks.

Sources