Port mirroring

Also known as: SPAN port

On this page 7

Port mirroring is a feature of managed network switches that copies frames seen on one or more source ports or VLANs and sends those copies to a designated destination port, where an analyzer, intrusion detection sensor or packet recorder can inspect them. In Ethernet & switching it is the standard way to observe live traffic without inserting a device into the forwarding path, and it is widely known as a SPAN port (Switched Port Analyzer), the name used by one major vendor that became common shorthand across Networking.

Mirroring exists because a switch, unlike a hub, delivers each unicast frame only to the port behind which the destination MAC address lives. A laptop plugged into a spare port therefore sees almost nothing of the conversations it needs to diagnose. Port mirroring restores that visibility selectively and on demand, at the cost of extra load on the switch and a copy that is not always complete.

How port mirroring copies traffic inside a switch

Port mirroring works by instructing the switching ASIC to replicate every frame that matches a session definition and enqueue the duplicate on the destination port. A mirror session names the sources, the direction of traffic and the destination. The original frame is forwarded normally, so production traffic is not interrupted, while the copy follows a separate, usually lower-priority path through the switch fabric.

Sources can be physical ports, link aggregation groups or entire VLANs. Direction matters: ingress mirroring copies frames as they enter a source port, egress mirroring copies them as they leave, and both directions gives a full picture of a conversation. The destination port normally stops participating in normal switching; it neither learns MAC addresses nor forwards ordinary traffic, which prevents mirrored frames from leaking back into the network.

The table below summarizes the elements that every mirror session defines and the effect each one has on what the analyzer receives.

ElementTypical optionsEffect on the copy
SourcePort, port channel, VLANDetermines which traffic is replicated
DirectionIngress, egress, bothControls whether one or both halves of a flow appear
DestinationLocal port, remote VLAN, tunnelDefines where the analyzer must be connected
FilterACL, VLAN list, sampling rateReduces volume to what the analyzer needs
EncapsulationNative, keep VLAN tags, GREDecides whether original tags and context survive
Components of a mirror session

Local, remote and encapsulated mirroring

Port mirroring comes in three main variants that differ in how far the copied traffic can travel. Local mirroring keeps source and destination on the same switch or stack. Remote mirroring carries the copy across Layer 2 trunks inside a dedicated VLAN, and encapsulated remote mirroring wraps it in an IP tunnel so it can cross routed Layer 3 boundaries.

Vendor names differ, but the concepts are consistent. RSPAN uses a reserved remote VLAN that must exist on every switch along the path, and ERSPAN encapsulates frames in GRE over IP, adding a header that records the session and, in later versions, a timestamp. Some platforms instead offer a generic tunnel-based mirroring option with similar behavior.

VariantTransport of the copyReachMain constraint
Local mirroringDirect to a local portSame switch or stackAnalyzer must be physically present
Remote VLAN mirroringDedicated VLAN over trunksLayer 2 domainRemote VLAN on every transit switch
Encapsulated mirroringGRE or similar IP tunnelAny routed networkHeader overhead and possible fragmentation
Port mirroring variants compared

Encapsulated mirroring is the most flexible, yet it adds roughly 50 bytes of overhead per frame, and full-size or jumbo frames may exceed the MTU of the transport path. When fragmentation is not possible, the copy is truncated or dropped, which an analyst can easily mistake for a fault in the monitored application.

Port mirroring compared with network taps and flow export

Port mirroring is one of three common ways to gain traffic visibility, and each answers a different need. A network tap is a passive or active hardware device inserted into a link that copies every bit, including physical errors. Flow export protocols such as NetFlow and IPFIX send summarized records of conversations rather than packets.

The comparison below shows why mirroring is attractive for quick, flexible access and why taps remain the choice for forensic-grade capture.

MethodCompletenessCost and effortBest fit
Port mirroringBest effort, may drop under loadBuilt into managed switchesTroubleshooting, flexible monitoring
Network tapEvery frame, including errored onesExtra hardware and a link outage to installSecurity sensors, legal evidence
Flow exportMetadata only, no payloadLow bandwidth, needs a collectorCapacity planning, traffic accounting
Visibility methods compared

Mirroring also differs from simply plugging into an unmanaged switch or a hub. Those devices either do not offer the feature at all or flood traffic indiscriminately, so the defined, filtered copy that a mirror session provides is effectively a privilege of managed switches.

Configuring a mirror session that delivers useful data

A useful mirror session starts with sizing the destination against the sources. A single 1 Gbit/s destination port cannot carry the combined traffic of two busy 1 Gbit/s source ports in both directions, which can reach 4 Gbit/s in total. Choosing a faster destination port, narrowing the sources or applying filters keeps the copy complete.

Engineers also decide whether the analyzer needs VLAN tags preserved. Without tags, traffic from several VLANs arrives mixed together and is hard to interpret. Many platforms strip tags by default on the destination port, so an explicit setting is often required.

SituationRecommended setupReason
Short troubleshooting on one serverLocal port, both directionsQuick to enable and easy to remove
Permanent intrusion detection feedTap or dedicated packet brokerGuaranteed completeness under load
Analyzer in a central data centerEncapsulated remote mirroringCopy crosses routed boundaries
Busy uplink with many VLANsVLAN source with ACL filterKeeps volume below destination capacity
Choosing a mirroring approach
  • Label every session and document it, because forgotten sessions silently consume capacity for years.
  • Check the platform limit; many switches support only two to four simultaneous sessions.
  • Use traffic filters to mirror only the protocols or hosts under investigation.

Limitations, risks and common mistakes

The most important limitation is that port mirroring is not lossless. When the switch is congested, it drops mirrored copies before production frames, and it typically discards malformed frames such as those with CRC errors before they are ever copied. Timing can also shift, so latency measured from a SPAN port is an approximation rather than a precise value.

Mirroring also creates a security exposure. Anyone with access to the destination port can read unencrypted credentials, voice calls and file transfers, so the analyzer should sit in a controlled location, and session changes should be restricted to authorized administrators and recorded in configuration audits.

SymptomLikely causeFix
Capture shows only one side of a flowSingle direction configuredMirror both ingress and egress
Gaps and retransmissions in the captureOversubscribed destination portFilter sources or use a faster port
Loop or broadcast storm after setupDestination port forwarding normallyDedicate the destination port to the session
Traffic from all VLANs looks mergedTags removed on egressEnable tag preservation on the destination
Common symptoms and fixes

In simple terms

A network switch normally acts like a careful mail sorter: each letter goes only to the person it is addressed to. That is efficient, but it means nobody else can see the mail. Port mirroring tells the switch to make photocopies of the letters going to and from certain people and drop those copies into a special box.

Whoever sits at that box, usually a monitoring computer, can then read the copies to find problems or suspicious activity. The original letters still arrive on time. The catch is that when the sorter gets very busy, some photocopies are skipped, so the copies are good for investigation but not a perfect record.

A practical example

A hospital network team receives complaints that a radiology viewing station takes several seconds to open images from the archive server. Both systems connect to the same 48-port access switch in the imaging department, and nothing in the switch counters looks wrong.

The engineer creates a local mirror session with the archive server port as the source, both directions selected, and an unused 10 Gbit/s port as the destination. A laptop running a packet analyzer captures ten minutes of traffic while a radiologist opens several studies. The capture reveals that each image request first waits for a DNS lookup that times out after five seconds before falling back to a secondary resolver.

After the DNS configuration on the viewing station is corrected, images open in under one second. The engineer then removes the mirror session and records the change, so the destination port does not remain an open window onto patient data traffic.