Subscribe to Windows IT Pro
April 18, 2001 12:00 AM

Making IP Address Changes from Within a Script

Windows IT Pro
InstantDoc ID #20278
Rating: (16)

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

Related Content:

ARTICLE TOOLS

Comments
  • Anonymous User
    7 years ago
    Jul 20, 2005

    The script works perfectly... but I still have one request: what do I have to add, so that netsh is closed and i return to the ususal "C:\\>"? I will do it remotely on another machine at startup, so it should close automaticaly.

  • Anonymous User
    7 years ago
    Jul 19, 2005

    Its realy great. Can someone tell how to add additional gateway address

  • Anonymous User
    7 years ago
    Jul 01, 2005

    super ...

  • Pedro
    7 years ago
    Jun 27, 2005

    How can i do this changes from static to dhcp on a win NT workstation?

  • Anonymous User
    7 years ago
    May 13, 2005

    Good articel

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.