While development and testing many times we need to change the IP addresses manually to a given IP and then switch back to Dynamic IP (DHCP). Doing it every time through GUI especially in Vista (finding the Network Option from Start, Right Click, Selecting Network Connections, then Right Click on the Interface, Choose IPV4, …) is tiresome and waste of time.

For doing it easily Windows exposes a great command called NETSH. NETSH exposes too many options, the help (/?) and online documentation runs for several pages. Because of this, every time I tried I was put off. Today I spent last 5 minutes and cracked this. For changing IP address, we need to use the NETSH INTERFACE IP command.

To display current IP settings (equivalent to your ipconfig command):

C:\>netsh interface ip show addresses 

Configuration for interface "Local Area Connection"
    DHCP enabled:                       No
    IP Address:                 
    Subnet Prefix:              (mask
    Default Gateway:         
    Gateway Metric:                    256
    InterfaceMetric:                     20

To change your IP Settings to DHCP:

C:\>netsh interface ip set address name="Local Area Connection" source=dhcp

To set IP to a manual config (replace with your own values):

C:\> netsh interface ip set address "Local Area connection" static 1

Here after static command, the first value is your IP Address, second is NetMask, third is Gateway and fourth is metric.

Similar to set address command in netsh interface ip there is set DNS command that can set the DNS values as well. If you put the above in a batch (.bat) file then you can just double-click on it everytime you want the IP config to be changed.

Categorized in:

Tagged in: