NETSH ?

How to use netsh command by examples?
Author: Abdel YEZZA
Date: 2006
Level: Intermediate

Be aware when executing these examples, some of them may change your network configuration and settings! Be sure what you are doing before trying examples. Please replace values to reflect your context and settings.

Purpose Command-line
Display all available netsh helpers that can be used locally netsh show helper

You should have an output like this:
GUID de l'application d'assistance      Nom de la DLL	Commande
--------------------------------------  -------------	--------
{00770721-44EA-11D5-93BA-00B0D022DD1F}  HNETMON.DLL  	bridge
{CC41B21B-8040-4BB0-AC2A-820623160940}  DGNET.DLL    	diag
{8B3A0D7F-1F30-4402-B753-C4B2C7607C97}  FWCFG.DLL    	firewall
{0705ECA1-7AAC-11D2-89DC-006008B0E5B9}  IFMON.DLL    	interface
{89D00931-1E00-11D3-8738-00600837C775}  IFMON.DLL    	ip
{05BB0FE9-8D89-48DE-B7BB-9F138B2E950C}  IPV6MON.DLL  	ipv6
{F1EFA7E5-7169-4EC0-A63A-9B22A743E19C}  IPV6MON.DLL  	6to4
{F1EFA7E5-7169-4EC0-A63A-9B22A743E19C}  IPV6MON.DLL  	isatap
{86A3A33F-4D51-47FF-B24C-8E9B13CEB3A2}  IPV6MON.DLL  	portproxy
{0705ECA2-7AAC-11D2-89DC-006008B0E5B9}  RASMONTR.DLL 	ras
{42E3CC21-098C-11D3-8C4D-00104BCA495B}  RASMONTR.DLL 	aaaa
{E0C5D007-D34C-11D2-9B76-00104BCA495B}  RASMONTR.DLL 	appletalk
{13D12A78-D0FB-11D2-9B76-00104BCA495B}  RASMONTR.DLL 	ip
{6FB90155-D324-11D2-9B76-00104BCA495B}  RASMONTR.DLL 	ipx
{69F21BC3-D349-11D2-9B76-00104BCA495B}  RASMONTR.DLL 	netbeui
{65EC23C0-D1B9-11D2-89E4-006008B0E5B9}  IPMONTR.DLL  	routing
{0705ECA0-7AAC-11D2-89DC-006008B0E5B9}  IPMONTR.DLL  	ip
{0705ECA3-7AAC-11D2-89DC-006008B0E5B9}  IPPROMON.DLL 	autodhcp
{0705ECA3-7AAC-11D2-89DC-006008B0E5B9}  IPPROMON.DLL 	dnsproxy
{0705ECA3-7AAC-11D2-89DC-006008B0E5B9}  IPPROMON.DLL 	igmp
{0705ECA3-7AAC-11D2-89DC-006008B0E5B9}  IPPROMON.DLL 	nat
{0705ECA3-7AAC-11D2-89DC-006008B0E5B9}  IPPROMON.DLL 	ospf
{0705ECA3-7AAC-11D2-89DC-006008B0E5B9}  IPPROMON.DLL 	relay
{0705ECA3-7AAC-11D2-89DC-006008B0E5B9}  IPPROMON.DLL 	rip
{0705ECA3-7AAC-11D2-89DC-006008B0E5B9}  IPPROMON.DLL 	routerdiscovery
{B1641451-84B8-11D2-B940-3078302C2030}  IPXMONTR.DLL 	ipx
{D3FCBA3A-A4E9-11D2-B944-00C04FC2AB1C}  IPXPROMN.DLL 	netbios
{D3FCBA3A-A4E9-11D2-B944-00C04FC2AB1C}  IPXPROMN.DLL 	rip
{D3FCBA3A-A4E9-11D2-B944-00C04FC2AB1C}  IPXPROMN.DLL 	sap
{BF563723-9065-11D2-BE87-00C04FC3357A}  WINSMON.DLL  	wins
{B2C0EEF4-CCE5-4F55-934E-ABF60F3DCF56}  IFMON.DLL    	winsock
Diagnose the IP configuration by pinging all network interfaces netsh diag show test

Do the same thing but display results in GUI
netsh diag gui

Show Firewall configuration
netsh firewall show config

Show network interfaces
netsh interface show interface

Show the current IP configuration
netsh interface ip show config

Add a DNS server at the position 3 of the interface called Connexion au réseau local
netsh interface ip add dns "Connexion au réseau local" 1.1.1.0 index=2

Add the ip address 192.168.1.145 with mask 255.255.255.0 to the interface called Local Area Connection
netsh interface ip add address "Local Area Connection" 192.168.1.145 255.255.255.0

Do the same thing as the previous example and specify in addition the default gateway and the metric

netsh interface ip add address "Local Area Connection" 192.168.5.145 255.255.255.0 gateway=192.168.1.130 gwmetric=2

Configure an interface called Local Area Connection to be a DHCP client

netsh set address name="Local Area Connection" source=dhcp

Set the IP configuration of the interface Local Area Connection the static IP address 192.168.5.132 with mask= 255.255.255.128, gateway= 192.168.5.130 and a metric of 1

netsh interface ip set address name="Local Area Connection" source=static addr=192.168.5.132 mask=255.255.255.128 gateway=192.168.5.130 gwmetric=1

Configure Internet Proxy (Proxy name [proxy_name] and used port [port])

Netsh winhttp proxy set [proxy_name]:[port]
Using a script to configure the interface called Local Area Connection with the following:
Ip configuration: static
IP address:  192.168.5.132
Mask: 255.255.255.128
gateway: 192.168.5.130
metric: 1
Primary DNS Server: 192.168.5.129
Enabe dynamic registration of the IP address for the primary DNS Server
Secondary DNS Server: 192.168.5.130
Wins Servers: NONE

1. Create a script file as Conf.scp with contents:
# ----------------------------------
# Interface IP Configuration
# ----------------------------------
pushd interface ip
		
# Interface IP Configuration for "Local Area Connection"
set address name="Local Area Connection" source=static addr=192.168.5.132 mask=255.255.255.128
set address name="Local Area Connection" gateway=192.168.5.130 gwmetric=1
set dns name="Local Area Connection" source=static addr=192.168.5.129 register=PRIMARY
add dns name="Local Area Connection" addr=192.168.5.130 index=2
set wins name="Local Area Connection" source=static addr=none
popd
# End of interface IP configuration

2. Run the command-line:
netsh -f Conf.scp

Rename the connection Local Area Connection to My connection

netsh interface set interface name="Local Area Connection" newname="My connection"

Disable the connection My connection

netsh interface set interface name="My connection" admin=disabled
   
How to use a script to add a DHCP scope, reconcile the scope and author the DHCP Server 1. Create a script file let say ConfDcope.scp with this content:
#	Set the DHCP server context
dhcp server 192.168.1.193
#	Add a new scope 
dhcp server add scope 192.168.1.192 255.255.255.192 "SCOPE EURO" "Euro DHCP scope"
#	Add an Ip range to the previous scope
dhcp server \\192.168.1.195 scope 192.168.1.192 add iprange 192.168.1.193 192.168.1.224
#	Add exclusion IP range
dhcp server \\192.168.1.195 scope 192.168.1.192 add excluderange 192.168.1.193 192.168.1.200
#	Add some options (006=DNS servers, 003=Router, 015=DNS Domain Name) 
dhcp server \\192.168.1.195 set optionvalue 006 IPADDRESS 192.168.1.193 192.168.1.194
dhcp server \\192.168.1.195 set optionvalue 003 IPADDRESS 192.168.1.193
dhcp server \\192.168.1.195 set optionvalue 015 STRING MyDomain.com
#	Reconcile the scope (reconcile the scope, then the DHCP server and finally authore the DHCP server)
dhcp server \\192.168.1.195 scope 192.168.1.192 initiate reconcile
dhcp server \\192.168.1.195 initiate reconcile
dhcp server \\192.168.1.195 initiate auth
2. Run the following command-line:
netsh -f ConfDcope.scp