Tag: Network Adapter

Get-NetIPConfiguration

Basic Networking PowerShell cmdlets cheatsheet to replace netsh, ipconfig, nslookup and more

Around 4 years ago I wrote a blog post about how to Replace netsh with Windows PowerShell which includes basic powershell networking cmdlets. After working with Microsoft Azure, Nano Server and Containers, PowerShell together with networking becomes more and more important. I created this little cheat sheet so it becomes easy for people to get started.

Basic Networking PowerShell cmdlets

Get-NetIPConfiguration

Get the IP Configuration (ipconfig with PowerShell)

Get-NetIPConfiguration

List all Network Adapters

Get-NetAdapter

Get a spesific network adapter by name

Get-NetAdapter -Name *Ethernet*

Get more information VLAN ID, Speed, Connection status

Get-NetAdapter | ft Name, Status, Linkspeed, VlanID

Get driver information

Get-NetAdapter | ft Name, DriverName, DriverVersion, DriverInformation, DriverFileName

Get adapter hardware information. This can be really usefull when you need to know the PCI slot of the NIC.

Get-NetAdapterHardwareInfo

Disable and Enable a Network Adapter

Disable-NetAdapter -Name "Wireless Network Connection"
Enable-NetAdapter -Name "Wireless Network Connection"

Rename a Network Adapter

Rename-NetAdapter -Name "Wireless Network Connection" -NewName "Wireless"

IP Configuration using PowerShell

PowerShell Networking Get-NetIPAddress

Get IP and DNS address information

Get-NetAdapter -Name "Local Area Connection" | Get-NetIPAddress

Get IP address only

(Get-NetAdapter -Name "Local Area Connection" | Get-NetIPAddress).IPv4Address

Get DNS Server Address information

Get-NetAdapter -Name "Local Area Connection" | Get-DnsClientServerAddress

Set IP Address

New-NetIPAddress -InterfaceAlias "Wireless" -IPv4Address 10.0.1.95 -PrefixLength "24" -DefaultGateway 10.0.1.1

or if you want to change a existing IP Address

Set-NetIPAddress -InterfaceAlias "Wireless" -IPv4Address 192.168.12.25 -PrefixLength "24"

Remove IP Address

Get-NetAdapter -Name "Wireless" | Remove-NetIPAddress

Set DNS Server

Set-DnsClientServerAddress -InterfaceAlias "Wireless" -ServerAddresses "10.10.20.1","10.10.20.2"

Set interface to DHCP

Set-NetIPInterface -InterfaceAlias "Wireless" -Dhcp Enabled

Clear DNS Cache with PowerShell

You can also manage your DNS cache with PowerShell.

List DNS Cache:

 
Get-DnsClientCache

Clear DNS Cache

 
Clear-DnsClientCache

Ping with PowerShell

PowerShell Networking Test-NetConnection Ping

How to Ping with PowerShell. For a simple ping command with PowerShell, you can use the Test-Connection cmdlet:

 
Test-Connection thomasmaurer.ch

There is an advanced way to test connection using PowerShell

Test-NetConnection -ComputerName www.thomasmaurer.ch

Get some more details from the Test-NetConnection

Test-NetConnection -ComputerName www.thomasmaurer.ch -InformationLevel Detailed

Ping multiple IP using PowerShell

1..99 | % { Test-NetConnection -ComputerName x.x.x.$_ } | FT -AutoSize

Tracert

PowerShell Tracert

Tracert with PowerShell

Test-NetConnection www.thomasmaurer.ch –TraceRoute

Portscan with PowerShell

PowerShell Portscan

Use PowerShell to check for open port

Test-NetConnection -ComputerName www.thomasmaurer.ch -Port 80
Test-NetConnection -ComputerName www.thomasmaurer.ch -CommonTCPPort HTTP

NSlookup in PowerShell

PowerShell Networking NSlookup

NSlookup using PowerShell:

Resolve-DnsName www.thomasmaurer.ch
Resolve-DnsName www.thomasmaurer.ch -Type MX -Server 8.8.8.8

Route in PowerShell

PowerShell Networking Route

How to replace Route command with PowerShell

Get-NetRoute -Protocol Local -DestinationPrefix 192.168*
Get-NetRoute -InterfaceAlias Wi-Fi
 
New-NetRoute –DestinationPrefix "10.0.0.0/24" –InterfaceAlias "Ethernet" –NextHop 192.168.192.1

NETSTAT in PowerShell

PowerShell Networking Netstat

How to replace NETSTAT with PowerShell

Get-NetTCPConnection
Get-NetTCPConnection –State Established

NIC Teaming PowerShell commands

Create a new NIC Teaming (Network Adapter Team)

New-NetLbfoTeam -Name NICTEAM01 -TeamMembers Ethernet, Ethernet2 -TeamingMode SwitchIndependent -TeamNicName NICTEAM01 -LoadBalancingAlgorithm Dynamic

SMB Related PowerShell commands

SMB PowerShell SMB Client Configuration

Get SMB Client Configuration

Get-SmbClientConfiguration

Get SMB Connections

Get-SmbConnection

Get SMB Mutlichannel Connections

Get-SmbMutlichannelConnection

Get SMB open files

Get-SmbOpenFile

Get SMB Direct (RDMA) adapters

Get-NetAdapterRdma

Hyper-V Networking cmdlets

Hyper-V PowerShell Get-VMNetwork Adapter

Get and set Network Adapter VMQ settings

Get-NetAdapterVmq
# Disable VMQ
Set-NetAdapterVmq -Enabled $false
# Enable VMQ
Set-NetAdapterVmq -Enabled $true

Get VM Network Adapter

Get-VMNetworkAdapter -VMName Server01

Get VM Network Adapter IP Addresses

(Get-VMNetworkAdapter -VMName NanoConHost01).IPAddresses

Get VM Network Adapter Mac Addresses

(Get-VMNetworkAdapter -VMName NanoConHost01).MacAddress

I hope you enjoyed it and the post was helpful, if you think something important is missing, please add it in the comments.



Cisco UCS C200 M2 with Windows Server 2008 R2 and Windows Server 8 #HyperV

Cisco UCS and Hyper-V Enable Stateless Offloads with NVGRE

As I already mentioned I did several Hyper-V and Microsoft Windows Server projects with Cisco UCS. With Cisco UCS you can now configure stateless offloads for NVGRE traffic which is needed for Hyper-V Network Virtualization.

Cisco UCS Manager supports stateless offloads with NVGRE only with Cisco UCS VIC 1340 and/or Cisco UCS VIC 1380 adapters that are installed on servers running Windows Server 2012 R2 operating systems.

To use this you have to create Ethernet Adapter Policy, and set the Configuring an Ethernet Adapter Policy to Enable Stateless Offloads with NVGREin the Resources area:

  • Transmit Queues = 1
  • Receive Queues = n (up to 8)
  • Completion Queues = # of Transmit Queues + # of Receive Queues
  • Interrupts = # Completion Queues + 2

And in the Option area set the following settings:

  • Network Virtualization using Generic Routing Encapsulation = Enabled
  • Interrupt Mode = Msi-X

Make also sure you have installed eNIC driver Version 3.0.0.8 or later.

For more information, see http:/​/​www.cisco.com/​c/​en/​us/​td/​docs/​unified_computing/​ucs/​sw/​vic_drivers/​install/​Windows/​b_​Cisco_​VIC_​Drivers_​for_​Windows_​Installation_​Guide.html.



Sort Network Adapter via PowerShell

Sort Windows Network Adapter by PCI Slot via PowerShell

If you work with Windows, Windows Server or Hyper-V you know that before Windows Server 2012 Windows named the network adapters randomly. This was a huge deal if you were trying to automate deployment of servers with multiple network adapters. And of course Hyper-V Servers normally have multiple network adapters. In Windows Server 2012 Microsoft had some different ways how this was fixed. First there is CDN (Consistent Device Naming) which allows hardware vendors to integrate the names so the OS can pick them up and the second one being the possibility of Hyper-V Converged Fabric which is basically making our lives easier by having less network adapters.

Well a lot of vendors have not integrated CDN or you have some old servers without CDN support. Back in May 2012 before the release of Windows Server 2012 I wrote a little Windows PowerShell script to sort network adapters in Windows Server 2008 R2 and Hyper-V Server 2008 R2 by using WMI (Configure Hyper-V Host Network Adapters Like A Boss). Now for a Cisco UCS project I rewrote some parts of the script to use Windows PowerShell in for Windows Server 2012, Windows Server 2012 R2 and Hyper-V.

First lets have a look how you can get the PCI slot information for network adapters, luckily there is now a PowerShell cmdlet for this.

 
Get-NetAdapterHardwareInfo

Now lets see how you can sort network adapters via Windows PowerShell.

 
Get-NetAdapterHardwareInfo | Sort-Object Bus,Function

This will get you a output like this:

Sort Network Adapter via PowerShell

Lets do a little loop to automatically name them:

$prefix = "NIC"
$netAdapters = Get-NetAdapterHardwareInfo | Sort-Object Bus,Function
$i = 0
 
foreach ($netAdapter in $netAdapters){
 
$interface = $netadapter | Get-NetAdapter
$old = $interface.Name
$newName = $prefix + $i
$interface | Rename-NetAdapter -NewName $newName
$i++
Write-Host "Rename" $old "to:" $newName
 
}

So this names all the network adapters to NIC1, NIC2, NIC3,…

So lets do a PowerShell function for this:

# ---------------------------------------------------------------------------------------------- #
# Powershell Sort-NetworkAdapter $Rev: 748 $
# (c) 2014 Thomas Maurer. All rights reserved.
# created by Thomas Maurer
# www.thomasmaurer.ch
# last Update by $Author: tmaurer $ on $Date: 2014-01-04 14:07:36 +0100 $
# ---------------------------------------------------------------------------------------------- #
 
function Sort-NetworkAdapter {
<# .SYNOPSIS This sorts and renames network adpaters by PCI slot .DESCRIPTION This sorts and renames network adapters sorted by PCI slot .EXAMPLE Sort-NetworkAdapter -prefix vnic -StartingNumber 0 This renames als NICs to vnic0, vnic1, vnic2,... .EXAMPLE Sort-NetworkAdapter -prefix nic -StartingNumber 1 This renames als NICs to nic1, nic2, nic3,... .PARAMETER prefix The Prefix of the network adapter name .PARAMETER StartingNumber The Number of the first network adapter #>
[CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='Low')]
param
(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='Which prefix you want to use?')]
[ValidateLength(1,20)]
[string]$prefix,
 
[Parameter(Mandatory=$False,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='Which Starting Number you want to use?')]
[int]$startingNumber = 1
)
 
begin {
write-verbose "Get netadpaters and sort them"
$netAdapters = Get-NetAdapterHardwareInfo | Sort-Object Bus,Function
}
 
process {
 
write-verbose "Rename netadapters"
 
foreach ($netAdapter in $netAdapters){
 
$interface = $netadapter | Get-NetAdapter
$old = $interface.Name
$newName = $prefix + $startingNumber
#$interface | Rename-NetAdapter -NewName $newName
$startingNumber++
Write-Host "Rename" $old "to:" $newName
 
}
}
}

Now you can run this by using Sort-NetworkAdapter for exmaple:

Sort-NetworkAdapter -prefix NIC

or

Sort-NetworkAdapter -prefix NIC -StartingNumber 0

You can also get this script from the Microsoft Technet Gallery or Script Center.



ConnectX-3 Pro NVGRE Offloading RDMA

Hyper-V Network Virtualization: NVGRE Offloading

At the moment I spend a lot of time working with Hyper-V Network Virtualization in Hyper-V, System Center Virtual Machine Manager and with the new Network Virtualization Gateway. I am also creating some architecture design references for hosting providers which are going to use Hyper-V Network Virtualization and SMB as storage. If you are going for any kind of Network Virtualization (Hyper-V Network Virtualization or VXLAN) you want to make sure you can offload NVGRE traffic to the network adapter.

Well the great news here is that the Mellanox ConnectX-3 Pro not only offers RDMA (RoCE), which is used for SMB Direct, the adapter also offers hardware offloads for NVGRE and VXLAN encapsulated traffic. This is great and should improve the performance of Network Virtualization dramatically.

NVGRE Offloading

More information on the Mellanox ConnectX-3 Pro:

ConnectX-3 Pro 10/40/56GbE adapter cards with hardware offload engines to Overlay Networks (“Tunneling”), provide the highest performing and most flexible interconnect solution for PCI Express Gen3 servers used in public and private clouds, enterprise data centers, and high performance computing.

Public and private cloud clustered databases, parallel processing, transactional services, and high-performance embedded I/O applications will achieve significant performance improvements resulting in reduced completion time and lower cost per operation.

Mellanox ConnectX-3 Pro

Benefits:

  • 10/40/56Gb/s connectivity for servers and storage
  • World-class cluster, network, and storage performance
  • Cutting edge performance in virtualized overlay networks (VXLAN and NVGRE)
  • Guaranteed bandwidth and low-latency services
  • I/O consolidation
  • Virtualization acceleration
  • Power efficient
  • Scales to tens-of-thousands of nodes

Key features:

  • 1us MPI ping latency
  • Up to 40/56GbE per port
  • Single- and Dual-Port options available
  • PCI Express 3.0 (up to 8GT/s)
  • CPU offload of transport operations
  • Application offload
  • Precision Clock Synchronization
  • HW Offloads for NVGRE and VXLAN encapsulated traffic
  • End-to-end QoS and congestion control
  • Hardware-based I/O virtualization
  • RoHS-R6

Virtualized Overlay Networks — Infrastructure as a Service (IaaS) cloud demands that data centers host and serve multiple tenants, each with their own isolated network domain over a shared network infrastructure. To achieve maximum efficiency, data center operators are creating overlay networks that carry traffic from individual Virtual Machines (VMs) in encapsulated formats such as NVGRE and VXLAN over a logical “tunnel,” thereby decoupling the workload’s location from its network address. Overlay Network architecture introduces an additional layer of packet processing at the hypervisor level, adding and removing protocol headers for the encapsulated traffic. The new encapsulation prevents many of the traditional “offloading” capabilities (e.g. checksum, TSO) from being performed at the NIC. ConnectX-3 Pro effectively addresses the increasing demand for an overlay network, enabling superior performance by introducing advanced NVGRE and VXLAN hardware offload engines that enable the traditional offloads to be performed on the encapsulated traffic. With ConnectX-3 Pro, data center operators can decouple the overlay network layer from the physical NIC performance, thus achieving native performance in the new network architecture.

I/O Virtualization — ConnectX-3 Pro SR-IOV technology provides dedicated adapter resources and guaranteed isolation and protection for virtual machines (VMs) within the server. I/O virtualization with ConnectX-3 Pro gives data center managers better server utilization while reducing cost, power, and cable complexity.

RDMA over Converged Ethernet — ConnectX-3 Pro utilizing IBTA RoCE technology delivers similar low-latency and high- performance over Ethernet networks. Leveraging Data Center Bridging capabilities, RoCE provides efficient low latency RDMA services over Layer 2 Ethernet. With link-level interoperability in existing Ethernet infrastructure, Network Administrators can leverage existing data center fabric management solutions.

Sockets Acceleration — Applications utilizing TCP/UDP/IP transport can achieve industry- leading throughput over 10/40/56GbE. The hardware-based stateless offload engines in ConnectX-3 Pro reduce the CPU overhead of IP packet transport. Socket acceleration software further increases performance for latency sensitive applications.

Storage Acceleration — A consolidated compute and storage network achieves significant cost-performance advantages over multi-fabric networks. Standard block and file access protocols can leverage Ethernet or RDMA for high-performance storage access.

Software Support – All Mellanox adapter cards are supported by Windows, Linux distributions, VMware, FreeBSD, Ubuntu, and Citrix XenServer. ConnectX-3 Pro adapters support OpenFabrics-based RDMA protocols and software and are compatible with configuration and management tools from OEMs and operating system vendors.