Switching Network Configurations with netsh

When I use wi-fi at at the coffee shop, I have to set up my laptop to use a dynamic IP address. When I am home, I like to use a static IP address. Going back and forth can be kind of a hassle. I used to have to change it by hand every time. I thought there must be a better way.  (I am not much of a networking expert, and setting up DHCP for one machine seemed like a bit of a hassle.)

I did some searching, and I found out about a tool on Windows called netsh. There is a very long page about is at Microsoft’s site, and a page at Wikipedia. You could make the changes in the GUI, and run the command netsh dump > $SOME_FILE_NAME to put them into a file, and later run netsh exec $SOME_FILE_NAME to set the interfaces.

I did a little bit of messing around, and I figured out all the commands I need to change back and forth. I put them in a text file, and I just copy and paste them into a DOS window when I need to.

To use a dynamic address:

netsh interface ip set address name="Local Area Connection" source=dhcp
netsh interface ip set dns name="Local Area Connection" source=dhcp register=PRIMARY
netsh interface ip set wins name="Local Area Connection" source=dhcp

To use a static address at home:

netsh interface ip set address name="Local Area Connection" source=static addr=192.168.1.7 mask=255.255.255.0
netsh interface ip set address name="Local Area Connection" gateway=192.168.1.3 gwmetric=0
netsh interface ip set dns name="Local Area Connection" source=static addr=192.168.1.3 register=PRIMARY
netsh interface ip add dns name="Local Area Connection" addr=192.168.1.5 index=2
netsh interface ip set wins name="Local Area Connection" source=static addr=none

 Image from Wikimedia, assumed allowed under Fair Use. Image from the Roman Vergil, a 5th century manuscript of poems by Virgil.

There are 325 words in this article.