Bharat Banate's Work Profile

View Bharat Banate's profile on LinkedIn

Tuesday, August 19, 2008

How to change IP address from the Windows command line

To do the same thing via the command line, use the netsh tool.

After some experimentation, I found that the following two commands were sufficient to give my machine a static IP address and have everything still work ok. The "interface ip set address" command changes the IP to 192.168.1.101 (this address is outside the range allocated by our DHCP server, therefore it will be different to what we had before) and I also had to provide the subnet mask (255.255.255.0), default gateway (192.168.1.5) and a gateway metric. The second command explicitly sets the DNS server to use for name resolution - normally this is done for us by the DHCP server.

netsh interface ip set address "Local Area Connection" static 192.168.1.101 255.255.255.0 192.168.1.5 1
netsh interface ip set dns "Local Area Connection" static 192.168.1.200 primary

To change the interface back to using DHCP and so have it allocated a different IP address

netsh interface ip set address "Local Area Connection" dhcp
netsh interface ip set dns "Local Area Connection" dhcp

1 comments:

Anonymous said...

Cool!
Its quite easy to work with these commands. Great job Bharat!

Thanks.