Windows: Show and configure network settings using netsh
Hi,
here is a set of netsh command lines which I use very often.
Show Interface configuration
netsh interface ipv4 show config
Only IP Addresses of all LAN adapters
netsh interface ipv4 show address
Show global TCP/IP Parameters
netsh interface ipv4 show global
Disable and enable a Interface
netsh int set int name="ethernet" admin=disabled
netsh int set int name="ethernet" admin=enabled
Show all network interfaces and its link state
netsh interface ipv4 show interfaces
Print the routing table
netsh interface ipv4 show route
Show all tcp connections
netsh interface ipv4 show tcpconnections
Which Multicast groups are joined
netsh interface ipv4 show joins
Show dynamic portrange for outgoing connections
netsh interface ipv4 show dynamicportrange protocol=tcp
Set a static IP Address (172.16.254.2), Subnet Mask (255.255.255.192) and Gateway (172.16.254.1) on a specific interface (Local Area Connection 2) persistent
netsh interface ipv4 set address name="Local Area Connection 2" static 172.16.254.2 255.255.255.192 172.16.254.1 store=persistent
and temporary up to the next reboot and the parameters at full length. After the reboot the IP Address is empty.
netsh interface ipv4 set address name="Local Area Connection 2" static address=172.16.254.2 mask=255.255.255.192 gateway=172.16.254.1 store=active
Set DNS Servers without a DNS check, the
set dnsservers
command supports only one server as argumentnetsh interface ipv4 set dnsservers name="Local Area Connection 2" source=static address="172.16.254.250" validate=no
you have to add a second DNS Server with the
add dnsservers
directivenetsh interface ipv4 add dnsservers name="Local Area Connection 2" address="172.16.254.251" validate=no index=2
Set IP Address assignment on Interface to DHCP
netsh interface ipv4 set address name="Local Area Connection 2" source=dhcp
and also the DNS Servers
netsh interface ipv4 set dnsservers name="Local Area Connection 2" source=dhcp
Add a route for subnet 172.16.1.0/24 over interface “Local Area Connection 2” and router 172.16.254.254
netsh interface add route prefix=172.16.1.0/24 interface="Local Area Connection 2" nexthop=172.16.254.254
Note: Since Windows Vista its not possible to set the dns search suffix with netsh, you have to use WMI for this.
To set the DNS search suffix use powershell and wmi.
Define your Domains
To set the DNS search suffix use powershell and wmi.
Define your Domains
1 | [string[]] $aDNSSearchSuffixes =@( "subdomain.domain1.local" , "subdomain.domain2.local" ) |
Get the WMI Class to invoke the static method SetDNSSuffixSearchOrder
1 | $oNetworkadapterConfiguration =[wmiclass] "Win32_NetworkadapterConfiguration" $oNetworkadapterConfiguration .SetDNSSuffixSearchOrder( $aDNSSearchSuffixes ) |
Or invoke the method directly by calling the Invoke-WmiMethod commandlet
1 | Invoke -WmiMethod -Class Win32_NetworkadapterConfiguration -Name SetDNSSuffixSearchOrder -ArgumentList @(@( "subdomain.domain1.local" , "subdomain.domain2.local" ), $null ) |
or
1 | Invoke -WmiMethod -Class Win32_NetworkadapterConfiguration -Name SetDNSSuffixSearchOrder -ArgumentList @( $aDNSSearchSuffixes , $null ) |
No comments:
Post a Comment