• Support Center
 

Configuring network settings from command line using netsh

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. Netsh also provides a scripting feature that allows you to run a group of commands in batch mode against a specified computer. Netsh can also save a configuration script in a text file for archival purposes or to help you configure other servers.

How to use Netsh?

To run a netsh command, you must start netsh from the Cmd.exe prompt and change to the context that contains the command you want to use.

Netsh.exe is available on Windows 2000, Windows XP and Windows Server 2003.

netsh
Syntax

netsh [-a AliasFile]
      [-c Context]
      [-r RemoteMachine]
      [Command | -f ScriptFile]

-a AliasFile Specifies that an alias file is used. An alias file contains both a list of netsh commands and an aliased version of each. You can use the aliased command to shorten a Netsh command.

-c Context Specifies the default context for subsequent commands at the Netsh command prompt. Without the -c option, the default context is the root context netsh>.

-r RemoteMachine Specifies that the Netsh commands are run against a remote computer, as specified by either its computer name or IP address.

Command Specifies the netsh command to run. You must specify a full Netsh command, complete with parameters. Otherwise, Netsh displays command-line help. If the -c option is used, the context is included as part of the Netsh command.

-f ScriptFile Specifies that all of the Netsh commands in the ScriptFile file are run.

Available commands after you have entered the netsh command (typing netsh at the prompt and pressing enter).

Discards changes made while in offline mode.

.. 	Goes up one context level.
? 	Displays a list of commands.
abort 	
add 	Adds a configuration entry to a list of entries.
alias 	Adds an alias.
bye 	Exits the program.
commit 	Commits changes made while in offline mode.
delete 	Deletes a configuration entry from a list of entries.
dump 	Displays a configuration script.
exec 	Runs a script file.
exit 	Exits the program.
help 	Displays a list of commands.
interface 	Changes to the `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 ‘ras’ context.
routing 	Changes to the ‘routing’ context.
set 	Updates configuration settings.
show 	Displays information.
unalias 	Deletes an alias.

Using Netsh

View your TCP/IP settings

netsh interface ip show config

Here is an example of command output:

Configuration for interface "Local Area Connection 1"
    DHCP enabled:                         Yes
    InterfaceMetric:                      1
    DNS servers configured through DHCP
    WINS servers configured through DHCP

Configuration for interface "Local Area Connection 2"
    DHCP enabled:                         No
    IP Address:                           192.168.0.20
    SubnetMask:                           255.255.255.0
    InterfaceMetric:                      1
    Statically Configured DNS Servers:    None
    Statically Configured WINS Servers:   None

Reset the TCP/IP Stack

netsh interface ip reset log.txt

A common use of netsh is to reset the TCP/IP stack to default, known-good parameters, a task that in Windows 98 required reinstallation of the TCP/IP adapter. In this mode you must provide a log file, which will be filled with what values netsh affected.

Delete arp cache

netsh interface ip delete arpcache

Deletes the arp cache entries for all available adapters (including the dial up adapter). Works well with DSL if you are able to ping the loopback address, and your own IP but nothing else.

netsh interface ip set address name="Local Area Connection" static 192.168.0.20 255.255.255.0 192.168.0.1 1

This command configures the interface named Local Area Connection with the static IP address 192.168.0.20, the subnet mask of 255.255.255.0, and a default gateway of 192.168.0.1

Configure your NIC to automatically obtain an IP address from a DHCP server:

netsh interface ip set address "Local Area Connection" dhcp

Configure DNS:

netsh interface ip set dns "Local Area Connection" static 192.168.0.200

Configure WINS:

netsh interface ip set wins "Local Area Connection" static 192.168.0.200

Configure your NIC to dynamically obtain it’s DNS settings:

netsh interface ip set dns "Local Area Connection" dhcp

Import/Export your TCP/IP settings

Export your current IP settings to a text file. Use the following command:

netsh -c interface dump > c:\\MySettings.txt

Import your IP settings and change them, just enter the following command in a Command Prompt window (CMD.EXE):

netsh -f c:\\MyAnotherSettings.txt

Configure firewall

Enable/Disable Windows firewall

netsh firewall set opmode mode=disable

This will disable the Windows Firewall, we could use the following command to enable it:

netsh firewall set opmode mode=enable

Add Ports to the Exception List

netsh firewall add portopening TCP 3234 MyTCPPort
netsh firewall add portopening UDP 7365 MyUDPPort

Add applications to exceptions list

netsh firewall add allowedprogram c:\MyProgram.exe

Again if we look at the exceptions list, MyProgram.exe has been added.

We can view the firewall configuration by running the following command:

netsh firewall show allowedprogram

Show network parameters

The following commands are available:

netsh diag show adapter

Displays all of the Adapters.

netsh diag show all

Displays all categories.

netsh diag show client

Displays all network clients.

netsh diag show computer

Displays computer information.

netsh diag show dhcp

Displays the DHCP servers for each adapter.

netsh diag show dns

Displays the DNS servers for each adapter.

netsh diag show gateway

Displays the default gateway servers for each adapter.

netsh diag show ieproxy

Displays Internet Explorer’s server name and port number.

netsh diag show ip

Displays the IP address for each adapter.

netsh diag show mail

Displays the mail server name and port number.

netsh diag show modem

Displays all modems.

netsh diag show news

Displays the news server name and port number.

netsh diag show os

Displays operating system information.

netsh diag show test

Displays all categories and performs all tests

netsh diag show version

Displays the Windows and WMI version.

netsh diag show wins

Displays the primary and secondary WINS servers for each adapter.

Launch the GUI Network Diagnostic Program

netsh diag gui
 
articles/configuring_network_settings_from_command_line.txt · Last modified: 2014/09/30 06:10 by LizardSystems