8

#PSTip VM Port mirroring in Hyper-V

Note: This tip requires PowerShell 3.0 or above.

In a physical switch environment, all traffic from selected ports can be duplicated and copied to a mirror port for capture and analysis, such as network diagnostic of a VM boot process or any network-related issues.

Starting in Windows Server 2012, port mirroring can be enabled on virtual switches as well. We can designate a vSwitch port as a monitoring port, and direct the vSwitch traffic going through this port to a specific VM.

The configuration is twofold–changes are needed on both, the source and destination VMs. This can be set under the Advanced Features page of the VMs’ network card.

portmirror

The following commands sets port mirroring on two VMs using the Set-VMNetworkAdapter. VM1 acts as the source VM, every packet sent or received by VM1 (on all all virtual network adapters) will be mirrored to VM2 virtual network card named Public . When you open a network monitor application on VM2, you will see captured traffic from both VMs.

Set-VMNetworkAdapter -VMName VM1 -PortMirroring Source
Set-VMNetworkAdapter -VMName VM2 -Name Public -PortMirroring Destination

Note that you can set multiple VMs as source machines and all their traffic will be copied to the destination VM.

Filed in: Columns, Tips and Tricks Tags: ,

8 Responses to "#PSTip VM Port mirroring in Hyper-V"

  1. john w says:

    Shay, being a network newbie…what tool would I use on the destination VM to capture and view packets being sent to it? WireShark or something similar?

  2. Casey says:

    Hi Shay, I know this is an old post. What if you need to mirror multiple ports to multiple ports? Just in Hyper-v.

Leave a Reply

Submit Comment

© 2016 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: