"For a complete guide to security, check out ''''Security+ Study Guide and DVD Training System'''' from Amazon.com"
What is Netsh?
Netsh is a command-line scripting utility that allows you to, either locally or remotely, display or modify the network configuration of a computer that is currently running. Using a simple example - What this boils down to is the fact that if you wanted to change an IP address on your PC, you will not have to navigate to the properties page seen below where you would normally changes those settings.
Not that this is a big deal, but by the end of this article you will see why (and how) Netsh can really save you some time, as it has done for me countless times while I work as an Engineer out in the field. Netsh provides a scripting feature that allows you to run a group of commands in batch mode against a specified computer which is essentially what I just mentioned, but also changing things other than just an IP address, but perhaps DNS server settings and so on. The power of this tool is amazingly strong once you know how to work with it and within it.
How to use Netsh
To use Netsh, you simply need to open a command prompt and launch it.
Start => Run => CMD
Enter Netsh and you will then be in the network shell. Type a ‘?’ and hit enter to examine the contents within.
The following commands are available:
Commands in this context:
|..||Goes up one context level.|
|?||Displays a list of commands.|
|abort||Discards changes made while in offline mode.|
|add||Adds a configuration entry to a list of entries.|
|alias||Adds an alias.|
|bridge||Changes to the `netsh bridge'' context.|
|bye||Exits the program.|
|commit||Commits changes made while in offline mode.|
|delete||Deletes a configuration entry from a list of entries.|
|diag||Changes to the `netsh diag'' context.|
|dump||Displays a configuration script.|
|exec||Runs a script file.|
|exit||Exits the program.|
|help||Displays a list of commands.|
|interface||Changes to the `netsh interface'' context.|
|offline||Sets the current mode to offline.|
|online||Sets the current mode to online.|
|popd||Pops a context from the stack.|
|pushd||Pushes current context on stack.|
|quit||Exits the program.|
|ras||Changes to the `netsh ras'' context.|
|routing||Changes to the `netsh routing'' context.|
|set||Updates configuration settings.|
|unalias||Deletes an alias.|
Within Netsh, you would need to change the context in which you are currently in so if you wanted to change settings within routing, type routing and then hit enter. You will then be in the routing context and hitting a ‘?’ shows you another list of things you can work within.
It may take you some time to navigate all the features but its worth a look. In this article (part I) and other subsequent articles, I will show you some of the more common features you can use as well as tips and tricks that you can use. Lets look at a very important one that I use all the time – how to change your IP address very quickly.
Using Netsh – trade secrets
For some, it may be a pain in the neck to launch netsh and use it, it would have been easier to navigate the GUI if you are familiar with it (hence why I don’t think it really catches on), but there are ways around that. With *.cmd files. Lets take a look at how to do this.
As an engineer, many times I am configuring routers and other devices that need my PC to be on the same subnet and I keep files on my desktop like this one:
To make this file, all you have to do is make a blank text file on your desktop and change the extension of it to *.cmd instead of *.txt. You will be asked if you want to change it, yes, you will want to do that. Another fact is, if you do not have all files visible to you, this change may not take place. Make sure you have the following setting adjusted:
You can get to this in Windows Explorer => Tools => Folder Options => View tab
Once you do get in, make sure that you are able to ‘see’ all the files and that you are not hiding any extensions.
Once you have made the file, you can edit it with Notepad. Simply add the following lines to the file:
netsh interface ip set address name="Local Area Connection"
netsh interface ip set address local static 10.1.1.2 255.255.255.0 10.1.1.1 1
Save the file and then you can run it by double clicking on it.
Once you do, you can look at your properties again and you will see that the changes took place. This is very helpful as you can make multiple files like QuickDNS, or something like that and have them all set up in a folder, you edit them quickly in notepad and then run them to change your settings. I find this to be much quicker than editing the GUI or using the Netsh tool in the Command Prompt.
If you would like to be notified when Robert Shimonski releases Part 2 please click here to sign up to our newsletter.