Configure TCP/IP Settings via Script

Friday, October 28, 2011

It is useful to be able to change the TCP/IP configuration for a client computer, such as a mobile computer, using the command prompt. For instance, if you have a mobile device that moves from network to network, using static IP settings, it is much easier to re-configure the computer using command line or a script than modifying the properties via the Network Properties GUI. The Netsh.exe utility makes this operation quick and easy.

Netsh.exe is a command-line scripting utility that allows you to, either locally or remotely, display or modify the network configuration. Netsh.exe also provides a scripting feature that allows you to run a group of commands in batch mode against a specified computer. Netsh.exe can also save a configuration script in a text file for archival purposes or to help you configure other servers.

Type the following command in a Command Prompt window (CMD.EXE):

netsh interface ip show config

Configure your computer's IP address and other TCP/IP related settings. For example:

The following command configures the interface named "Local Area Connection" with the static IP address 192.168.0.1, the subnet mask of 255.255.255.0, and a default gateway of 192.168.0.254:

netsh interface ip set address name="Local Area Connection" static 192.168.0.100 255.255.255.0 192.168.0.1 1

Other TCP/IP settings:

netsh interface ip set dns "Local Area Connection" static 192.168.0.100 index=1

netsh interface ip set dns "Local Area Connection" static 192.168.0.101 index=2

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

* For mobile computers needing static IP settings depending on the network: First, configure the static IP address and other settings for the first network.  Use the following command:

netsh -c interface dump > c:Network1.txt

Set up the settings for the second Network using the command above.

netsh -c interface dump > c:Network2.txt

To quickly set up your computer at any network location, open a command prompt and type the following command:
netsh -f c:Network1.txt

OR

netsh -f c:Network2.txt

OR use these commands

netsh exec c:Network1.txt
netsh exec c:Network2.txt

To configure your adapter back to DHCP, use the following command:
netsh interface ip set address "Local Area Connection" dhcp

Did you find the page informational and useful? Share it using one of your favorite social sites.

Recommended Books & Training Resources

Advanced VBScript for Microsoft Windows Administrators Microsoft WSH and VBScript Programming for the Absolute Beginner