Using the NETSH command
The "netsh" command as many features such as changing firewall settings, bridging connections, changing routing, WINS, DNS, Winsock, ...etc. The list goes on and on. This topic will show you how to do the following:
- Set static IP
- Set static WINS
- Set Static DNS
- Reset Network configuration
- Automating the Process
Using the netsh command
To use the netsh command, open a command window and type netsh. Your command prompt should then display "netsh>" . (To learn more about "netsh" just type "help" or "?" at the "netsh>" prompt) To move around in the netsh, you would just type where you want to go. So if you want to get into the interface you would just type "interface" at the "netsh>" prompt. To move back, just type "..".
Set a Static IP Address
To set a static IP Address on a PC, you would use the following syntax.
"netsh interface ip set address name="[interface]" static [IP] [MASK] [GATEWAY] [METRICS]"Here's an example to set a network card to use IP 10.10.70.2, Mask 255.255.0.0, Gateway 10.10.10.1, Metrics 1.
netsh interface ip set address name="Local Area Connection" 10.10.70.2 255.255.0.0 10.10.10.1 1It's just that easy!
Set a static WINS address.
To set a static WINS address on a PC, you would use the following syntax. This command will set both a primary and secondary address
netsh interface ip add wins name=[interface] addr=[address] index=1 > [output file]netsh interface ip add wins name=[interface] addr=[address] index=2 >> [output file]
Here's an example to set a network card to use a primary WINS of 10.44.44.2 and secondary 10.22.44.2 and output status to a text file called winsStatus.txt
netsh interface ip add wins name="Local Area Connection" addr=10.44.44.1 > winsStatus.txtnetsh interface ip add wins name="Local Area Connection" addr=10.22.44.1 >> winsStatus.txt
Set a static DNS address
To set a static DNS address on a PC, you would use the following syntax. This is very similar to the WINS command.
netsh interface ip add dns name=[interface] addr=[address] index=1 > [output file]netsh interface ip add dns name=[interface] addr=[address] index=1 > [output file]
Here's an example to set a network card to use a primary DNS of 10.43.44.1 and a secondary 10.23.44.1 and output to a text file Called dnsStatus.txt
netsh interface ip add DNS name="Local Area Connection" addr=10.44.44.1 > dnsStatus.txtnetsh interface ip add wins name="Local Area Connection" addr=10.44.44 2 > dnsStatus.txtResetting the Interface (Removing IP, WINS, and DNS settings)
To reset the network interface card, you would use the following syntax.
netsh interface ip reset [name=]<string>
Here’s an example:
Netsh interface ip reset resetlog.txt
Automating the Process
You can do it many ways, here’s is how to do it using a batch file and using a scripting language used in Auto It. (http://www.autoitscript.com/)
Using AutoIt
Here’s a script that reads an INI file to set the DNS and WINS on a PC for the “Local Area Connection”