This is not something you should have to do often, but it certainly is a nice thing to know. Especially if you have to do this on a large group of computers. Being able to do this from command line in a script is nice.
The reason I had to do it was I migrated a DEV server from one VMWare cluster at my company’s home office over to a new DEV cluster at our offsite data center. I was moving it to a new subnet, so I had to change the static IP address of the virtual server. For some reason, when I powered it on and logged in, I was unable to access Network and Sharing Center. It would open up, but nothing would display. It was almost like it hung up on something. I mentioned it to the person who owned the machine, but they shrugged it off like that was just how it was.
Since it is a personal DEV machine, and not a production server I decided not to spend a lot of time troubleshooting it. I did still have to give this thing a new IP address though. Lucky for me, the command line was working fine!
In order to change the IP address and DNS information from command line on a Windows server, you need to use the netsh command. To change the IP address, subnet mask and default gateway run the following:
netsh interface ip set address name="Local Area Connection" static 10.4.0.30 255.255.255.0 10.4.0.1
Of course, you will have to change the interface name, and IP information for your environment. The next thing you may want to change is the DNS server information. To change the Primary DNS server run the following:
netsh interface ip set dnsserver "Local Area Connection" static 10.4.0.100 primary
Once again, change this to match your environment. Now to add additional DNS servers run the following:
netsh interface ip add dnsserver "Local Area Connection" static 10.4.0.101
Notice in the above example, I have replaced set with add. Smart right? Once you have those set, you can now check your configuration by running ipconfig /all.
Have any other command line tips you want to share? Hit us up in the comments!