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




You must log on before posting a comment.

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

Reader Comments

Just what I was looking for, THANKS!!

Howard Davis

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

Anu Skariah

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

This is great. Thanks

Sean Lee

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

Donovan

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

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

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

patrick

It works great! Thanks to the author

martin

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

Surej

What do we need to enter for multiple DNS/WINS address entries? I.E. Primary and Alternate...we are using four address for DNS and WINS...

carleokj

to add additional dns and wins

netsh interface ip add dns "local area connection" 3.3.3.3

netsh interface ip add wins "local area connection" 3.3.3.3

Anonymous User

Can someone tell mehow I remove the DNS settings (to obtain automatic) when i use netsh to set dhcp

Anonymous User

Article Rating 5 out of 5

It all works pefectly exept the removal of the dns.

When i use the netsh dhcp > it doesnt change my dns settings to automatic .. how do i do that?

Anonymous User

To obtain a dynamic DNS, use: netsh interface ip set dns "Local Area Connection" dhcp

Anonymous User

See More Comments  1   2   3 
 
 

ADS BY GOOGLE