Using 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.

Usage: netsh [-a AliasFile] [-c Context] [-r RemoteMachine] [-u [DomainName\]Use
rName] [-p Password | *]
[Command | -f ScriptFile]

The following commands are available:

Commands in this context:
? – Displays a list of commands.
add – Adds a configuration entry to a list of entries.
advfirewall – Changes to the `netsh advfirewall’ context.
branchcache – Changes to the `netsh branchcache’ context.
bridge – Changes to the `netsh bridge’ context.
delete – Deletes a configuration entry from a list of entries.
dhcpclient – Changes to the `netsh dhcpclient’ context.
dnsclient – Changes to the `netsh dnsclient’ context.
dump – Displays a configuration script.
exec – Runs a script file.
firewall – Changes to the `netsh firewall’ context.
help – Displays a list of commands.
http – Changes to the `netsh http’ context.
interface – Changes to the `netsh interface’ context.
ipsec – Changes to the `netsh ipsec’ context.
lan – Changes to the `netsh lan’ context.
mbn – Changes to the `netsh mbn’ context.
namespace – Changes to the `netsh namespace’ context.
nap – Changes to the `netsh nap’ context.
netio – Changes to the `netsh netio’ context.
p2p – Changes to the `netsh p2p’ context.
ras – Changes to the `netsh ras’ context.
rpc – Changes to the `netsh rpc’ context.
set – Updates configuration settings.
show – Displays information.
trace – Changes to the `netsh trace’ context.
wcn – Changes to the `netsh wcn’ context.
wfp – Changes to the `netsh wfp’ context.
winhttp – Changes to the `netsh winhttp’ context.
winsock – Changes to the `netsh winsock’ context.
wlan – Changes to the `netsh wlan’ context.

The following sub-contexts are available:
advfirewall branchcache bridge dhcpclient dnsclient firewall http interface ips
ec lan mbn namespace nap netio p2p ras rpc trace wcn wfp winhttp winsock wlan
Netsh contexts
————–
Netsh utility interacts with others using dynamic-link library files. Each Netsh helper DLL provides an extensive set of features called a context, which is a group of commands specific to this DLL networking component. These contexts extend the functionality of netsh. For ex., Dhcpmon.dll provides netsh the context and set of commands necessary to configure and manage DHCP settings.

For more information about Netsh contexts, use this command in the netsh shell:

netsh>show helper
DLL Filename Command
———— ——-
HNETMON.DLL bridge
DGNET.DLL diag
FWCFG.DLL firewall
IFMON.DLL interface
IFMON.DLL ip
IPV6MON.DLL ipv6
IPV6MON.DLL 6to4
IPV6MON.DLL isatap
IPV6MON.DLL portproxy
RASMONTR.DLL ras
RASMONTR.DLL aaaa
RASMONTR.DLL appletalk
RASMONTR.DLL ip
RASMONTR.DLL ipx
RASMONTR.DLL netbeui
IPMONTR.DLL routing
IPMONTR.DLL ip
IPPROMON.DLL autodhcp
IPPROMON.DLL dnsproxy
IPPROMON.DLL igmp
IPPROMON.DLL nat
IPPROMON.DLL ospf
IPPROMON.DLL relay
IPPROMON.DLL rip
IPPROMON.DLL routerdiscovery
IPXMONTR.DLL ipx
IPXPROMN.DLL netbios
IPXPROMN.DLL rip
IPXPROMN.DLL sap
IFMON.DLL winsock
netsh>
List of available netsh contexts
——————————–
AAAA – commands for AAAA
Shows and sets the configuration of the Authentication, Authorization, Accounting, and Auditing (AAAA) database used by the Internet Authentication Service (IAS) and the Routing and Remote Access service.

DHCP – commands for DHCP
Administers DHCP servers and provides an equivalent alternative to console-based management.

Diag – diagnostic (diag) commands
Administers and troubleshoots operating system and network service parameters.

Interface – commands for Interface IP
Configures the TCP/IP protocol (including addresses, default gateways, DNS servers, and WINS servers) and displays configuration and statistical information.

RAS – commands for RAS
Administers remote access servers.

Routing – commands for Routing
Administers Routing servers.

WINS – commands for WINS
Administers WINS servers.
Displaying all of the adapter
—————————–
To display all of the adapters in the computer with their current IP addresses to determine the correct adapter name, type the following command:

Netsh interface ip show config

Change static address to DHCP
—————————–
To switch the specified adapter from a static address to DHCP, type the following command:

netsh interface ip set address “Local Area Connection” dhcp

Displays just the DNS server addresses
————————————–
netsh interface ip show dnsservers

Displays the TCP connections
—————————-
netsh interface ip show tcpconnections

Shows only TCP statistics
————————
netsh interface ip show tcpstats

Displays the UDP connections
—————————-
netsh interface ip show udpconnections

Shows only UDP statistics
————————–
netsh interface ip show udpstats

Change to a static address
—————————-
netsh interface ip set address “Local Area Connection” static ipaddr subnetmask gateway metric

eg:- netsh interface ip set address “Local Area Connection” static 192.168.0.10 255.255.255.0 192.168.0.1 1

Dump all the network information
——————————–
netsh dump

Import your IP settings
———————–

netsh -f c:\location1.txt or netsh exec c:\location2.txt

some examples

>netsh interface ipv4 show compartments

Id Interfaces Routes HopLimit
—— ———- —— ——–
1 3 15 128

>netsh interface ipv4 show global
Querying active state…

General Global Parameters
———————————————
Default Hop Limit : 128 hops
Neighbor Cache Limit : 256 entries per interface
Route Cache Limit : 128 entries per compartment
Reassembly Limit : 536866752 bytes
ICMP Redirects : enabled
Source Routing Behavior : dontforward
Task Offload : enabled
Dhcp Media Sense : enabled
Media Sense Logging : disabled
MLD Level : all
MLD Version : version3
Multicast Forwarding : disabled
Group Forwarded Fragments : disabled
Randomize Identifiers : enabled
Address Mask Reply : disabled

Current Global Statistics
———————————————
Number of Compartments : 1
Number of NL clients : 7
Number of FL providers : 4

>netsh interface ipv4 show ipstats
MIB-II IP Statistics
——————————————————
Forwarding is: Disabled
Default TTL: 128
In Receives: 2390189991
In Header Errors: 26416400
In Address Errors: 7060
Datagrams Forwarded: 0
In Unknown Protocol: 123
In Discarded: 8170
In Delivered: 2364039939
Out Requests: 2522875753
Routing Discards: 0
Out Discards: 2071
Out No Routes: 1462
Reassembly Timeout: 60
Reassembly Required: 0
Reassembled Ok: 0
Reassembly Failures: 0
Fragments Ok: 0
Fragments Failed: 0
Fragments Created: 0
>netsh interface ipv4 show route

>netsh interface ipv4 show subinterfaces

MTU MediaSenseState Bytes In Bytes Out Interface
—— ————— ——— ——— ————-
4294967295 1 0 8784 Loopback Pseudo-Interface 1
1500 1 1352228023139 1700849690717 Local Area Connection 2
1300 1 61980 13485540 Local Area Connection* 9

Advertisements

Posted on May 20, 2014, in Windows. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: