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


May 2001

Making IP Address Changes from Within a Script


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

One of the Windows 2000 features that I've found most useful is the capability to change from dynamic to static IP addressing on a workstation without needing to reboot. The ability to execute the change from within a script would make this new feature even more useful. Is this type of execution possible?

To make IP address changes from within a script, you can use Win2K's multipurpose Net Shell (Netsh) command. This command provides several functions that relate to viewing and changing IP addressing on a Win2K system. For example, to change a system from static IP addressing to dynamic DHCP-based addressing, open a command prompt and enter the following command:

netsh interface ip set address "<connection name>" dhcp

where connection name is the name of the LAN adapter on which you're making the IP address configuration change. (By default, this adapter is called local area connection, but it might have a different name on machines with multiple LAN adapters or on machines that an administrator has manually renamed.)

To make the reverse change—that is, to change a connection or adapter from DHCP-configured addressing to static addressing—enter the following command:

netsh interface ip set address "<connection name>" static <ip_address>
<netmask> <gateway> <metric>

where ip_address is the static IP address you wish to assign to the connection, netmask is the subnet mask (e.g., 255.255.255.0) associated with the IP address, gateway is the default gateway (if any) on the local IP subnet, and metric is an optional numeric value (e.g., 1, 2) that defines the number of hops to the default gateway (if one exists). For example, to change from DHCP-based addressing to the static IP address 10.1.1.2, mask 255.255.255.0, and gateway 10.1.1.1 (metric 1), you'd enter

netsh interface ip set address "local area connection" 
static 10.1.1.2 255.255.255.0 10.1.1.1 1

End of Article



Reader Comments
Just what I was looking for, THANKS!!

Howard Davis November 10, 2003


How do you change the IP address of a remote system on the network using the same command?

Anu Skariah November 12, 2003


To change the IP address of a remote system on the network ad the required IP address in same command and then the same command can be made to run at the remote system by adding it to the schduler of the remote system.

Deepak kumar November 17, 2003


This is great. Thanks

Sean Lee March 29, 2004


Really great! But what if you need to specify statis DNS settings? What do you add to the command?

Donovan April 11, 2004


This sounds very good, is it possible to use this with script logons to allow or disable internet access?
I have a domain with 3 Ou's but only one of them should have access to the internet , no matter what machine they use... maybe it's possible to assign a logon script using Group Policy to change the default gateway?? (!)

Bruno Quintas April 20, 2004


For dns settings i think it would me netsh interface ip set dns <serverMode> <address>... I havent tried this yet but it looks correct.

Ex.
set dns "Local Area Connection" static 10.0.0.1

Sid April 21, 2004


How can change the subnetmask, the rest should not be changed

patrick May 05, 2004


It works great! Thanks to the author

martin June 03, 2004


That is what i was looking for, Made my life eassy. Thanks a lot !!

Surej July 06, 2004


 See More Comments  1   2   3   4 

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
Command Prompt Tricks

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

WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Where is Microsoft NetMeeting in Windows XP?

...


Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events WinConnections and Microsoft® Exchange Connections

Deep Dive into Windows Server 2008 R2 presented by John Savill

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting 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


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
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement