Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


July 2007

Change IP Settings in a Snap


RSS
Subscribe to Windows IT Pro | See More Tips Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

After spending a frustrating evening manually changing the IP settings for my Ethernet and wireless network adapters numerous times, I decided to create a tool that would automatically change IP settings. I wanted it to

  • be a command-line tool

  • have easily remembered syntax

  • make default assumptions

  • allow me to change all the IP settings at once

  • allow me to change the IP settings for any card in my system

  • have integrated Help and version information

The result is SetIP.cmd. This script lets you quickly and easily change the IP address, subnet mask, gateway, and DNS server for Ethernet and wireless network adapters. When you have more than one adapter of a type (e.g., two Ethernet network adapters, two wireless network adapters) the script will display the adapters one by one and let you select the one you want to configure. I've used SetIP.cmd with various versions of Windows XP. It should work fine with Windows 2000, but I haven't done much testing in that environment. Initial reports indicate possible problems with using it on server OSs, such as Windows Server 2003. (I wrote this script for use on client OSs.)

SetIP.cmd uses the Netsh Interface IP commands to change IP settings. Although these commands are useful, their syntax is complicated and difficult to remember. So, SetIP.cmd generates the Netsh Interface IP commands for you. You just need to provide basic information on the command line using syntax that's much easier to remember.

SetIP.cmd uses the following defaults, unless you specify otherwise on the command line:

  • It sets the IP settings for an Ethernet network adapter.

  • It sets the IP address to 192.168.1.2.

  • It sets the subnet mask to 255.255.255.0.

  • It sets the gateway to netAddress.1, where netAddress is the first three octets of the IP address in a 24-bit subnet (i.e., 192.168.1.1 with the default IP address).

  • It sets the DNS server to 4.2.2.2.

You can change the Ethernet network adapter, IP address, subnet mask, gateway, and DNS defaults by modifying the :PREP section, which Listing 1 shows. (You can download the entire script from the Windows IT Pro Web site.)

To launch SetIP.cmd, you follow the syntax

Setip [dhcp | <IPAddr>]
  [mask <SubnetMask>] 
  [gw <DefaultGateway>] 
  [dns <DnsServerAddr>] 
  /w /nodns 

If you launch the script with no parameters, all the default values just specified are set. When you want the DHCP server to select the IP address, you specify dhcp. When you want a static IP address, you specify that IP address.

The script has three other optional parameters: mask, gw, and dns. You use the mask parameter when you want to change the subnet mask to a value other than the default. The gw parameter lets you set the gateway to a value other than the default. You use the dns parameter to set the DNS server to a value other than the default.

The script also has two optional switches: /w and /nodns, which are case-sensitive. If you're configuring a wireless network adapter rather than an Ethernet network adapter, you include the /w switch. You use the /nodns switch if you want to skip configuring the DNS server setting. (During testing, I often just need to check network connectivity and therefore don't want Netsh to configure the DNS server setting.)

Let's look at some examples. Suppose you want to set an Ethernet network adapter's IP address to 192.168.1.2, subnet mask to 255.255.255.0, gateway to 192.168.1.1, and DNS server to 4.2.2.2. Because the address, subnet mask, gateway, and DNS server settings are the defaults, you just need to run the command

Setip 

If you want to set a wireless network adapter's IP address to 10.20.30.5 and set its subnet mask, gateway, and DNS server settings to the defaults (255.255.255.0, 10.20.30.1, and 4.2.2.2, respectively), you'd use the command

Setip 10.20.30.5 /w 

If you want to set an Ethernet network adapter's IP address to 192.168.2.9, subnet mask to 255.255.255.128, gateway to 192.168.2.2, and DNS server to 192.168.2.12, you'd run the command

Setip 192.168.2.9 
  mask 255.255.255.128 
  gw 192.168.2.2 
  dns 192.168.2.12 

If you want the DHCP server to automatically set all the IP settings, you'd use the command

Setip dhcp 

Because I frequently use SetIP.cmd to check network connectivity, I often first set the Ethernet network adapter to a static IP address, then change it back to an IP address generated by the DHCP server, ignoring the DNS server setting in both instances. In this scenario, the commands look like

Setip 10.1.1.2 gw 10.1.1.254 /nodns
  Setip dhcp /nodns 

SetIP.cmd evolved out of my personal testing in various environments and has served me well. I hope you find it equally as useful.

—Matthew C. Miller, CTO, Stability Networks

End of Article



Reader Comments
What am I missing?

I don't see how this script can work?

jimoler September 19, 2007 (Article Rating: )


Jimoler: Can you explain a little more what you don't understand? If I know more about the problem, I can ask the author to respond to your question.

AnneG_editor September 21, 2007 (Article Rating: )


where can I get SetIP.cmd ?

shint99 April 15, 2008 (Article Rating: )


Near the top of the page, you'll find a blue "Download the Code Here" button. Just click it to download the 96113.zip file, which contains the SetIP.cmd script.

KBemowski April 16, 2008 (Article Rating: )


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
The website is down because someone removed the X-Box

What happens when a manager mistakes a server for a games console. ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

Microsoft Kills OneCare, Will Launch Free Security Solution

Microsoft on Tuesday announced that it would retire its $50-a-year security subscription product, Windows Live OneCare, and replace it with a free solution codenamed "Morro." Unlike OneCare, however, Morro will focus only on core anti-malware features and ...


Related Articles Use Netsh to Easily Change IP Addresses

Task Automation Whitepapers Essential Guide to E-discovery and Recovery for Microsoft Exchange

Continuous Data Protection and Recovery for Microsoft Exchange

Protecting (You and) Your Data with Exchange Server 2007

Related Events Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


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 Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing