Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


January 2004

Cool Things to Do with Netsh

Change almost any network configuration setting with this powerful tool
RSS
Subscribe to Windows IT Pro | See More Resource Kit Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

The Netsh command is a powerful command-line tool for Windows Server 2003, Windows XP, and Windows 2000. Netsh is available in the Microsoft Windows 2000 Server Resource Kit and is standard in Windows 2003 and XP. Netsh lets you change almost any network configuration setting as well as document network configurations. You can use the command in a batch file or from its own command shell. Netsh has a useful Help system that you can access by adding /? to almost any of its subcommands. Here are 10 cool things that you can use Netsh to do.

10. Show TCP/IP settings—The command

netsh interface ip show config

shows the system's current TCP/IP configuration settings. You can see whether the system is using DHCP or static addressing as well as view the system's current IP address, subnet mask, gateway address, and DNS servers.

9. Change network configuration—Netsh can change the current network configuration. The command

netsh interface ip set
  address "Local Area 
  Connection" static 
  192.168.0.10 255.255.255.0
  192.168.0.254

sets the IP address of the system configuration Local Area Connection to 192.168.0.10, the subnet mask to 255.255.255.0, and the gateway address to 192.168.0.254. This use of Netsh comes in handy for laptops that must switch between static and dynamic addressed networks.

8. Use a dynamic DHCP assigned address—The command

netsh interface ip set
  address "Local Area 
  Connection" dhcp

sets the IP address of the Local Area Connection system configuration to use DHCP addressing.

7. Change a DNS server address—When you change the system's IP address type, you almost always have to change the DNS server's address as well. The command

netsh interface ip set dns
  "Local Area Connection" 
  static 192.168.0.2

configures the Local Area Connection to use a DNS server whose address is 192.168.0.2.

6. Dynamically assign the DNS server address—When you switch to dynamic DHCP addressing, you typically also want the DNS server address to be assigned dynamically. The command

netsh interface ip set dns 
"Local Area Connection" dhcp

sets the Local Area Connection interface to use a DHCP-assigned DNS address.

5.Configure a WINS server—Netsh also lets you configure WINS servers. The following command configures a system's Local Area Connection interface to use a WINS server that has the IP address 192.168.100.3.

netsh interface ip set wins 
  "Local Area Connection" 
  static 192.168.100.3

4. Work with other interfaces—Netsh works with DHCP, Internet Authentication Service (IAS), and RAS interfaces as well as the local network interface. The command

netsh dhcp dump > dhcpcfg.dat

dumps the local DHCP server's configuration to the dhcpcfg.dat file. You can use this file in conjunction with Netsh to recreate the DHCP server.

3. Work with remote systems—One of Netsh's best hidden features is its ability to work with remote systems. The command

netsh set machine remotecomputer

sets the current computer to a different system on the network.

2. Save the current configuration—The Interface Dump subcommand saves your current network configuration and generates a script that you can use to regenerate the configuration. The command

netsh interface dump > 
  mycfg.dat

redirects the Dump command to the mycfg.dat file.

1. Restore network configuration—The Netsh Exec command runs a Netsh script file. The command

netsh exec mycfg.dat

restores to your system the network configuration data that the preceding sample command saved.

End of Article



Reader Comments
How do you use netsh to set more than one DNS server? We've been able to use the following to set multiple WINS servers:

netsh interface ip set wins name="Local Area Connection" static 192.168.1.1
netsh interface ip add wins name="Local Area Connection" 192.168.1.2

However, this syntax doesn't work for setting multiple DNS servers.

Thanks in advance for any help.



Robert Logan February 10, 2004


In order to add multiple DNS servers, use the following syntax:

add dns "Local Area Connection" 10.0.0.1
add dns "Local Area Connection" 10.0.0.3 index=2

index=2 adds the IP as a secondary dns server.

Cameron Fairbairn May 06, 2004


The sentence "The Netsh command is a powerful command-line tool for Windows Server 2003, Windows XP, and Windows 2000. Netsh is available in the Microsoft Windows 2000 Server Resource Kit and is standard in Windows 2003 and XP." should be changed to "The Netsh command is a powerful command-line tool that is installed by default for Windows Server 2003, Windows XP, and Windows 2000."

Netsh is included with Windows 2000, not as part of the Windows 2000 Server Resource Kit.

Thanks.

Joseph Davies May 25, 2004


How migrate DHCP and Wins of Windows 2000 Active Directory to Windows 2003 Active Directory

martin June 04, 2004


Roger, could you please provide the complete statement for doing the multiple DNS bit that you wrote, please...

I can be PM'd at wyc@bigfoot.com

THANKS!

wYc88 June 17, 2004


Is it possible to use netsh to disable and then enable an interface? Been trying to figure out a way do do that from a cmd line.
thx

tschreier June 27, 2004


tschreier: I'm not sure if Devcon can do this, but I've done this before using another powerful command line utility: DevCon.exe (check out http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272 for a copy). Devcon DDK (Device/Driver Developer Kit) Tool is a command line version of Device Manager. To disable a network connection, you're actually disabling the network adapter associated with the connection. Using some customized scripting and devcon.exe, you can identify the adapter and enable or disable it on the fly. One word of advice, be sure to "escape" the ampersands (&) in the device IDs using the "hat" charector (^) when running it from the command line by specifying them as ^& otherwise you could end up in a major bind!

yhamade June 30, 2004


#4 netsh dhcp dump > dhcpcfg.dat
should read
netsh dump dhcp > dhcpcfg.dat

Kalidor July 01, 2004


The commands in the article need to be corrected as follows:

10. netsh interface ip show config

09. Netsh interface ip set address name=”Local Area Connection” source=static addr=192.168.0.10 mask=255.255.255.0 gateway=192.168.0.1 gwmetric=1

08. Netsh interface ip set address name=”Local Area Connection” source=dhcp

07. Netsh interface ip set dns name=”Local Area Connection” source=static addr=192.168.0.2 register=none

06. netsh interface ip set dns name="Local Area Connection" source=dhcp

05. Netsh interface ip set wins name=”Local Area Connection” source=static addr=192.168.100.3

To configure WINS from DHCP:
Netsh interface ip set wins name=”Local Area Connection” source=dhcp

04. netsh dump dhcp > dhcpcfg.dat

03. OK

02. netsh dump interface > mycfg.dat

01. OK

Robert Holland July 03, 2004


This DEVCON.EXE don't exit with ad usable errorlevel...in every cases it return "0" :-(
I can't find a IFCONFIG porting for win32 :-) ...

mauroedp July 07, 2004


 See More Comments  1   2   3   4   5 

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
What You Need to Know About Microsoft's x64 Server Product Plans

What do Longhorn Server, Windows Compute Cluster Server, and Windows Vista have in common? The x64 platform. ...

WinInfo Short Takes: 4th of July Special Edition

An often irreverent look at some of the week's other news, including a shortened work week thanks to the 4th of July, expensive Windows 7 pricing, Bing's modest monthly gains, IE 8 heading to work, Steve Jobs back at Apple, and so much more ...

How can I stop and start services from the command line?

...


Windows OSs Whitepapers Why SaaS is the Right Solution for Log Management

Related Events WinConnections and Microsoft® Exchange Connections

No Do Overs – Get Virtualization Right the First Time

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format

Test Drive IT Solutions and Get Free Music Downloads
Solve your toughest IT problems with these free downloads and receive 5 free music downloads!


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home asp.netPRO Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement | Reprints and Licensing