Still Very Much Alive and Kicking - netsh
Jul 13th 2007Desmond LeeWindows Server 2012/ 2008 R2/ Server Core & Windows & Scripting
netsh.exe is a nifty little command-line utility that is part of each and every copy of Windows since Windows 2000. It supports configuration of core networking parameters such as settings for TCP/IP, Windows firewall, network access protection (NAP), winhttp and IPSec, to name a few, and this list is ever expanding with each new release.
As the configuration of the majority of Windows Server 2008 Core settings typically gets executed on the command-line, netsh will once again play a pivotal role on this optimized platform. In fact, once you learn the basics, it will no longer look that intimidating and the skills can be applied to any supported legacy Windows versions.
So let’s get started. You can run netsh interactively or combine all the elements in one statement and execute them directly off the command-line. We shall examine the latter in the following but you can always break them up and interactively type them at the netsh prompt.
A common task is to modify the TCP/IPv4 settings of a host machine by assigning a static IP address, subnet mask and a default gateway (optional) i.e. configure TCP/IP Settings using netsh. Before making any changes, it would be useful to query the current settings:
C:\>netsh interface ipv4 show config “Local Area Connection”
Configuration for interface “Local Area Connection”
DHCP enabled: No
IP Address: 10.20.53.2
Subnet Prefix: 10.20.53.0/8 (mask 255.0.0.0)
InterfaceMetrix: 10
Statically Configured DNS Servers: None
Register with which suffix: Primary only
Statically Configured WINS Servers: None
To actually change or configure basic TCP/IPv4 settings with netsh, do the following:
C:\>netsh interface ipv4 set address “Local Area Connection” static 192.168.80.11 255.255.255.0 192.168.80.254
C:\>netsh interface ipv4 show config “Local Area Connection”
Configuration for interface “Local Area Connection”
DHCP enabled: No
IP Address: 192.168.80.11
Subnet Prefix: 192.168.80.0/24 (mask 255.255.255.0)
InterfaceMetrix: 10
Statically Configured DNS Servers: None
Register with which suffix: Primary only
Statically Configured WINS Servers: None
For DNS, another step is essential:
C:\>netsh interface ipv4 set dnsserver “Local Area Connection” static 192.168.80.10 primary
C:\>netsh interface ipv4 show dnsserver “Local Area Connection”
Configuration for interface “Local Area Connection”
Statically Configured DNS Servers: 192.168.80.10
Register with which suffix: Primary only
Any modifications take effect immediately as long as the syntax and values are valid. The entire netsh statement can be saved in a batch file or as a script file (netsh exec script.txt) for execution in bulk on multiple hosts across the network, for instance.
Tested on Windows Server 2008 June 2007 CTP. Replace ipv4 with ip on older Windows versions.
Technorati tags: Longhorn, Windows Server 2008, Windows Server Core 2008, Windows
No Comments »
Leave a Reply
You must be logged in to post a comment.