
Port Mirroring in vSphere (also called SPAN or vSphere Distributed Switch Port Mirroring) is a feature that lets you copy network traffic from one or more virtual switch ports and send it to another port for monitoring, analysis, or security inspection.
In simple words it allows you to watch or analyze VM network traffic without interrupting it.
In this lab tutorial we will be configuring port mirroring feature in vSphere.
Lab Environment Overview
Lab Infrastructure:
- ESXi 7.0 Host: 192.168.91.129
- vCenter Server: 192.168.91.130
- Network: 192.168.91.0/24
Lab Objectives:
- Create a vSphere Distributed Switch (VDS)
- Configure distributed port groups
- Set up port mirroring sessions
- Test and verify traffic mirroring
- Troubleshoot common issues
Prerequisites:
- Administrative access to vCenter Server
- At least 2 virtual machines for testing
- Network packet analyzer (Wireshark or tcpdump)
What the Lab Covers:
- Environment Preparation – Accessing vCenter and preparing test VMs
- Distributed Switch Setup – Creating and configuring VDS (required for port mirroring)
- Port Group Configuration – Setting up source and monitor port groups
- Port Mirroring Configuration – Step-by-step session creation
- Testing & Verification – Using tcpdump/Wireshark to verify mirrored traffic
- Troubleshooting – Common issues and solutions
- Performance Testing – Validating capture effectiveness
Part 1: Environment Preparation
Step 1.1: Access vCenter Server
- Open a web browser and navigate to your vCenter Server:
https://192.168.91.130
- Log in with your administrator credentials
- Username:
administrator@vsphere.local(or your custom SSO username) - Password: [Your vCenter password]
- Username:
- Navigate to the vSphere Client interface
Step 1.2: Verify ESXi Host
- In vCenter, click on Menu → Hosts and Clusters
- Verify your ESXi host (192.168.91.129) is visible and connected
- Check host status shows “Connected” with a green icon
- Note the host version (should be ESXi 7.0.x)
Step 1.3: Prepare Test Virtual Machines
You’ll need at least two VMs for this lab:
- VM1 (Source): The VM whose traffic we’ll mirror
- VM2 (Monitor): The VM that will capture mirrored traffic
If you don’t have these VMs, create them:
- Right-click on your ESXi host → New Virtual Machine
- Create two lightweight VMs (minimal Linux or small Windows VMs work well)
- Ensure both VMs can communicate on the same network
Recommended VM Configuration:
- Small Linux VMs (Ubuntu Server or CentOS minimal)
- 1 vCPU, 2GB RAM each
- 20GB disk space
- Single network adapter
Part 2: Create vSphere Distributed Switch
Port mirroring requires a vSphere Distributed Switch (VDS). Standard switches don’t support this feature.
Step 2.1: Create the Distributed Switch
- In vCenter, click Menu → Networking
- Right-click on your datacenter → Distributed Switch → New Distributed Switch
- Name and Location:
- Name:
Lab-VDS-01 - Location: Select your datacenter
- Click Next
- Name:
- Select Version:
- Choose 7.0.0 (to match your ESXi version)
- Click Next
- Configure Settings:
- Number of uplinks: 2 (default)
- Network I/O Control: Enabled (recommended)
- Create a default port group: Checked
- Default port group name:
Lab-VDS-01-PG - Click Next
- Ready to Complete:
- Review settings
- Click Finish
Step 2.2: Add ESXi Host to Distributed Switch
- Select your newly created Lab-VDS-01 switch
- Click the Actions menu → Add and Manage Hosts
- Select Task:
- Choose Add hosts
- Click Next
- Select Hosts:
- Click + New hosts
- Select your ESXi host (192.168.91.129)
- Click OK, then Next
- Select Network Adapter Tasks:
- Check Manage physical adapters
- Check Manage VMkernel adapters
- Click Next
- Manage Physical Network Adapters:
- Assign at least one physical NIC to the distributed switch uplinks
- Click on a physical adapter (e.g., vmnic1)
- Select Assign uplink → choose Uplink 1
- Click Next
- Manage VMkernel Adapters:
- If you have VMkernel adapters to migrate, assign them to appropriate port groups
- Otherwise, click Next
- Migrate VM Networking:
- Skip for now or migrate existing VMs if desired
- Click Next
- Impact Analysis:
- Review the impact (should show no issues)
- Click Next, then Finish
Step 2.3: Create Additional Port Groups
Create dedicated port groups for our lab:
- Right-click Lab-VDS-01 → Distributed Port Group → New Distributed Port Group
- Create Source Port Group:
- Name:
Lab-Source-PG - Click Next
- VLAN type: None (or VLAN 0)
- Click Next, then Finish
- Name:
- Create Monitor Port Group:
- Repeat the process
- Name:
Lab-Monitor-PG - Click Next
- VLAN type: None
- Click Next, then Finish
Step 2.4: Configure Monitor Port Group Settings
The monitoring VM requires promiscuous mode enabled:
- Select Lab-Monitor-PG
- Click the Configure tab → Settings → Policies
- Click Edit
- Expand Security
- Set the following:
- Promiscuous mode: Accept
- MAC address changes: Accept
- Forged transmits: Accept
- Click OK
Part 3: Migrate VMs to Distributed Switch
Step 3.1: Move VM1 (Source VM)
- Go to Menu → VMs and Templates
- Right-click on VM1 → Edit Settings
- Click on Network adapter 1
- Change the network to Lab-Source-PG
- Click OK
Step 3.2: Move VM2 (Monitor VM)
- Right-click on VM2 → Edit Settings
- Click on Network adapter 1
- Change the network to Lab-Monitor-PG
- Click OK
Step 3.3: Verify Network Connectivity
- Power on both VMs
- Log into each VM
- Assign IP addresses in the same subnet:
- VM1:
192.168.91.201/24 - VM2:
192.168.91.202/24
- VM1:
- Test connectivity:
# From VM1
ping 192.168.91.202
# From VM2
ping 192.168.91.201
Part 4: Configure Port Mirroring
Step 4.1: Create Port Mirroring Session
- In vCenter, go to Menu → Networking
- Select Lab-VDS-01
- Click the Configure tab
- Select Settings → Port Mirroring
- Click Add (+ icon)
Step 4.2: Configure Session Parameters
Session Name and Type:
- Session name:
Lab-Mirror-Session-01 - Session type: Distributed Port Mirroring
- Normal I/O on destination ports: Not Allowed (recommended)
- Session enabled: Checked
- Snapshot length: 65535 (captures full packets)
- Sampling rate: 1 (captures every packet)
Traffic Direction:
- Select Ingress and Egress (captures both incoming and outgoing traffic)
Click Next
Step 4.3: Select Source Ports
- Click + Add under Sources
- Select Ports
- Expand Lab-Source-PG
- Select the port that VM1 is connected to
- You’ll see entries like “Lab-Source-PG-{number}”
- Find the port showing your VM1’s MAC address or name
- Click OK
- Click Next
Note: To identify which port your VM is using:
- Look at the VM name column
- Or check VM’s network adapter details to find the port ID
Step 4.4: Select Destination Port
- Click + Add under Destinations
- Select Ports
- Expand Lab-Monitor-PG
- Select the port that VM2 is connected to
- Click OK
- Click Next
Step 4.5: Complete Configuration
- Review your settings:
- Session name: Lab-Mirror-Session-01
- Type: Distributed Port Mirroring
- Source: VM1’s port on Lab-Source-PG
- Destination: VM2’s port on Lab-Monitor-PG
- Direction: Ingress and Egress
- Status: Enabled
- Click Finish
Step 4.6: Verify Port Mirroring Status
- The new session should appear in the Port Mirroring list
- Status column should show Enabled
- Note the Session ID for reference
Part 5: Test Port Mirroring
Step 5.1: Install Traffic Capture Tool on Monitor VM
For Linux Monitor VM:
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install tcpdump
# CentOS/RHEL
sudo yum install tcpdump
# Or install Wireshark for GUI analysis
sudo apt-get install wireshark
For Windows Monitor VM:
- Download and install Wireshark from https://www.wireshark.org/
Step 5.2: Start Packet Capture
On Linux Monitor VM (VM2):
# Capture all traffic on the network interface
sudo tcpdump -i eth0 -w /tmp/mirror_capture.pcap
# Or view traffic in real-time
sudo tcpdump -i eth0 -n
On Windows Monitor VM:
- Open Wireshark
- Select your network adapter
- Click the shark fin icon to start capture
Step 5.3: Generate Traffic from Source VM
On Source VM (VM1):
# Generate ICMP traffic
ping 192.168.91.1 -c 100
# Generate HTTP traffic
curl http://www.example.com
# Generate continuous traffic
ping 8.8.8.8
# Or generate SSH traffic
ssh user@192.168.91.130
Step 5.4: Verify Mirrored Traffic
On Monitor VM (VM2):
You should see traffic from VM1 appearing in your packet capture, including:
- ICMP packets to various destinations
- HTTP requests
- DNS queries
- Any other traffic generated by VM1
Expected output in tcpdump:
14:23:45.123456 IP 192.168.91.201 > 8.8.8.8: ICMP echo request, id 1234, seq 1
14:23:45.145678 IP 8.8.8.8 > 192.168.91.201: ICMP echo reply, id 1234, seq 1
14:23:46.234567 IP 192.168.91.201.52345 > 93.184.216.34.80: Flags [S], seq 123456
Key Observation: You should see traffic between VM1 and external hosts, NOT just traffic between VM1 and VM2. This confirms port mirroring is working correctly.
Part 6: Advanced Configuration Options
Option A: Configure ERSPAN (Encapsulated Remote SPAN)
If you have a remote analyzer, configure ERSPAN:
- Edit your port mirroring session
- Change Session type to Encapsulated Remote Mirroring (L3) Source
- Configure additional parameters:
- Encapsulation VLAN ID:
100 - IP Address: [Your remote analyzer IP]
- Click Next and complete configuration
- Encapsulation VLAN ID:
Option B: Filter Specific Traffic
To mirror only specific traffic types:
- Some filtering can be achieved using distributed firewall rules
- Or use VLANs to segment traffic before mirroring
- Post-capture filtering in Wireshark using display filters:
ip.src == 192.168.91.201
tcp.port == 80
icmp
Option C: Multiple Source Ports
To mirror traffic from multiple VMs:
- Edit your existing port mirroring session
- In the Sources section, click + Add
- Select additional ports from the same or different port groups
- All selected source traffic will mirror to the same destination
Part 7: Monitoring and Troubleshooting
Step 7.1: Verify Port Mirroring Status
In vCenter:
- Navigate to Lab-VDS-01 → Configure → Port Mirroring
- Verify session status is Enabled
- Check source and destination port assignments
Via ESXi Shell/SSH:
# SSH to your ESXi host
ssh root@192.168.91.129
# List distributed switches
esxcli network vswitch dvs vmware list
# View port mirroring configuration
esxcfg-vswitch -l
# Check network statistics
esxtop
# Press 'n' for network view
Step 7.2: Common Issues and Solutions
Issue 1: No Traffic Appearing in Monitor VM
Solutions:
- Verify promiscuous mode is enabled on Lab-Monitor-PG
- Confirm both VMs are powered on
- Check that correct ports are selected as source/destination
- Verify port mirroring session is enabled
- Ensure monitor VM’s network adapter is in promiscuous mode
Issue 2: Partial Traffic Capture
Solutions:
- Check sampling rate is set to 1 (captures every packet)
- Verify snapshot length is 65535 for full packet capture
- Check direction is set to “Ingress and Egress”
- Verify no CPU resource constraints on ESXi host
Issue 3: Cannot Find VM Ports
Solutions:
- Ensure VMs are connected to distributed port groups
- Power on VMs before selecting source/destination ports
- Check VM network adapter is connected (checkbox in VM settings)
- Refresh the port mirroring configuration page
Issue 4: Performance Impact
Solutions:
- Reduce sampling rate if capturing high-bandwidth traffic
- Limit snapshot length to capture only headers (set to 128 bytes)
- Mirror only specific port groups rather than all traffic
- Monitor ESXi host CPU and network utilization
Step 7.3: Verification Commands
On Monitor VM (verify capture):
# Check interface is receiving packets
ifconfig eth0
# Look for RX packets incrementing
# Verify promiscuous mode
ip link show eth0
# Should show PROMISC flag
# Test with tcpdump
sudo tcpdump -i eth0 -c 10
# Should show packets immediately
On ESXi Host (via SSH):
# Check distributed switch configuration
esxcli network vswitch dvs vmware list
# View port statistics
esxcli network port stats get
Part 8: Performance Testing
Step 8.1: Measure Capture Effectiveness
Generate Known Traffic:
# On VM1 (Source)
ping 192.168.91.1 -c 1000 -i 0.1
# On VM2 (Monitor) - count packets
sudo tcpdump -i eth0 icmp | wc -l
Expected: Close to 2000 packets (1000 requests + 1000 replies)
Step 8.2: Bandwidth Test
Install iperf3:
# On both VMs
sudo apt-get install iperf3
Generate Traffic:
# On VM1 - Run server
iperf3 -s
# On another VM - Run client
iperf3 -c 192.168.91.201 -t 30
# On VM2 - Monitor capture
sudo tcpdump -i eth0 port 5201 -w iperf_test.pcap
Analyze the capture to verify all traffic is mirrored.
Part 9: Lab Cleanup (Optional)
Step 9.1: Disable Port Mirroring
- Navigate to Lab-VDS-01 → Configure → Port Mirroring
- Select Lab-Mirror-Session-01
- Click Remove (trash icon)
- Confirm deletion
Step 9.2: Remove Distributed Switch (Optional)
If you want to return to standard switching:
- Migrate VMs back to standard switch port groups
- Remove ESXi host from distributed switch
- Delete distributed switch
Warning: Only do this if you’re certain you don’t need the VDS.
- Design
