Update: Check out the MS TechNet docs for more netsh commands and how-tos here.
While listening to an archived Hanselminutes podcast about Scott's Top-10 Windows Utilities, I was intrigued to hear him mention netsh, the command-line util for setting your network interface properties. As he points out, it's true that not many folks know the power of netsh to control your IP, DNS, routing tables and more.
I've been using netsh myself for some time to get around a minor XP annoyance: Switching WiFi networks. I assign an IP to my laptop when I am connected to my home router, but at the office I connect via DHCP. Ordinarily, this switching would involve opening up the properties for my connection and changing the IP and DNS configurations according to the network I was on. This is so onerous, that there are even utilities out there (that people are charging $$$ for) to make this more seamless.
I'm cheap and I believe in a working hack that saves me a few bucks!
So, I crafted a couple of batch files to run netsh commands that would allow me to switch between my home and office WiFi routers with ease. Here's the first one for establishing a DHCP connection:
netsh interface ip set address name="Wireless Network Connection" dhcp
netsh interface ip set dns name="Wireless Network Connection" dhcp
I saved this in my root folder under the filename "wireless_dhcp.bat". Note the address and dns named connections that are used in this batch - this refers to the named connection for the wireless card. You can confirm the name of your connection by running an “ipconfig /all” and checking the ethernet adapter item for your WiFi NIC.
Next, here is the batch file that I used for my internal network:
netsh interface ip set address name=”Wireless Network Connection” source=static addr=192.168.0.100 mask=255.255.255.0 gateway=192.168.0.1 gwmetric=1
netsh interface ip set dns name=”Wireless Network Connection” source=static addr=206.47.244.102 register=primary
netsh interface ip set dns name=”Wireless Network Connection” source=static addr=206.47.244.135 index=2
This is a little more interesting. The first command sets up my IP address, mask and gateway -- I use a non-standard config for VPN access. The next two commands set my DNS servers - the primary and secondary. It's a little counter-intuitive the way this is set with “index=2”, but this allows for a range of DNS servers to be added and accessed by index.
I saved this batch as “wireless_home.bat” in my root folder. Now, when I want to switch networks, I just drop down to the command prompt and run the appropriate batch to switch my network settings.
Cool. But it could be notched up. This is where another util Scott mentions came in handy: WinKey. This bad-boy (which also happens to be out-of-print, so get it from the link fast) lets you configure windows key shortcuts to run commands automagically. I added two shortcuts for Win-A and Win-B to run my home and DHCP batch scripts respectively.
Total time to do this hack is about 10 minutes and it's zero cost. With a little creativity and some review of the netsh commands, you could put together some pretty complex on-the-fly changes for your own NIC configs.
Have fun!