交換式乙太網 **單播流量僅在源/目的埠間轉發**,第三方監聽設備 (IDS/IPS/審計/協議分析器/取證) 無法直接見到流量。SPAN (Switch Port Analyzer) 將指定源埠/VLAN 流量 **複製** 到目的埠 (連接分析設備),實現**無側帶、非侵入式**監控。
set span 6/1 7/1 ! 源模組/埠 6/1 → 目的 7/1 (單向 rx)
set span 6/1 7/1 both ! 雙向 (rx+tx)
set span 6/1-5 7/1 ! 多源埠
set span vlan 10 7/1 ! 源 VLAN 10 所有流量
monitor session 1 source interface Gi1/0/1 - 5 both ! 源埠範圍,雙向
monitor session 1 source vlan 10,20 ! 或源 VLAN
monitor session 1 destination interface Gi1/0/24 ! 目的埠 (需為 Access/Trunk)
! 進階選項
monitor session 1 filter vlan 100,200 ! 僅鏡像特定 VLAN (源為 Trunk 時)
monitor session 1 destination interface Gi1/0/24 encapsulation replicate ! 保留原封裝 (含 VLAN tag)
monitor session 1 source remote vlan 900 ! RSPAN 源端 (見下文)
**核心機制**:建立專用 **RSPAN VLAN** (僅承載鏡像流量),源交換機將鏡像流量打標進 RSPAN VLAN → Trunk 透傳 → 目的交換機從 RSPAN VLAN 取出送至分析埠。
! === 所有參與交換機 (源/中繼/目的) 同步建立 RSPAN VLAN ===
vlan 900
remote-span ! 關鍵:標記為 RSPAN VLAN
exit
! === 源交換機 (被監控側) ===
monitor session 1 source interface Gi1/0/1 both
monitor session 1 destination remote vlan 900 reflector-port Gi1/0/2 ! 反射埠 (僅本地轉發用,不連設備)
! 注意:反射埠必須為物理埠、非 Trunk、無其他配置
! === 中繼交換機 (透傳) ===
! 僅需確保 VLAN 900 在所有 Trunk 上允許通過 (allowed vlan add 900)
! **關鍵:啟用 VTP Pruning 或手工 prune vlan 900 off 不需要的 Trunk**,防止鏡像流量淹沒無關鏈路!
! === 目的交換機 (分析設備接入側) ===
monitor session 2 source remote vlan 900
monitor session 2 destination interface Gi1/0/24 encapsulation replicate
**現象**:配置 RSPAN 後,核心交換機上聯 Trunk 負載飆升至 300Mbps+,業務大量丟包。
**根因**:未啟用 VTP Pruning,RSPAN VLAN 900 被泛洪至 **所有 Trunk**,包括無分析設備的接入/匯聚鏈路。
**解決**:`switchport trunk pruning vlan 900` (或 `vlan 900` 下 `no vtp pruning` 視平台) 將 RSPAN VLAN 從無關 Trunk 修剪;或手工 `switchport trunk allowed vlan remove 900`。
**教訓**:**RSPAN VLAN 必須嚴格限制傳播範圍**,僅在源→目的路徑上允許。
RSPAN 受限於 L2 域。ERSPAN (Cisco 專有/標準化中) 將鏡像流量 **GRE 封裝 (IP 承載)** 發送至遠端 IP 位址 (分析平台/雲端),**跨越 L3 邊界、路由網路、數據中心互聯**。配置關鍵:`monitor session type erspan-source/destination`、源/目的 IP、ERSpan ID、MTU 調整 (含 GRE 頭 24-32 bytes)。