---
title: "CISCO交换机端口镜像配置"
author: "eseries"
date: "2009-07-06T15:10:27Z"
tags: []
slug: "cisco"
draft: false
lastmod: "2009-07-14T11:40:13Z"
id: 420821
url: "https://eseries.iteye.com/blog/420821"
---

先解释一下端口镜像：端口镜像简单的说，就是把交换机一个（数个）端口（源端口）的流量完全拷贝一份，从另外一个端口（目的端口）发

出去，以便网络管理人员从目的端口通过分析源端口的流量来找出网络存在问题的原因。  
cisco的端口镜像叫做SWITCHED PORT ANALYZER，简称SPAN（仅在IOS系统中，下同），因此，端口镜像仅适用于以太网交换端口。Cisco的SPAN

分成三种，SPAN、RSPAN和VSPAN，简单的说，SPAN是指源和目的端口都在同一台机器上、RSPAN指目的和源不在同一交换机上，VSPAN可以镜像

整个或数个VLAN到一个目的端口。

配置方法：  
1\. SPAN  
(1) 创建SPAN源端口  
monitor session session\_number source interface interface-id \[, | -] \[both | rx | tx]  
\*\*session\_number,SPAN会话号，我记得3550支持的最多本地SPAN是2个，即1或者2。  
\*\*interface-id \[, | -]源端口接口号，即被镜像的端口，交换机会把这个端口的流量拷贝一份，可以输入多个端口，多个用“,”隔开，

连续的用“-”连接。  
\*\*\[both | rx | tx]，可选项，是指拷贝源端口双向的(both)、仅进入(rx)还是仅发出(tx)的流量，默认是both。

(2)创建SPAN目的端口  
monitor session session\_number destination interface interface-id \[encapsulation {dot1q \[ingress vlan vlan id] | ISL

\[ingress]} | ingress vlan vlan id]  
\*\*一样的我就不说了。  
\*\*session\_number要和上面的一致。  
\*\*interface-id目的端口，在源端口被拷贝的流量会从这个端口发出去，端口号不能被包含在源端口的范围内。  
\*\*\[encapsulation {dot1q | isl}]，可选，指被从目的端口发出去时是否使用802.1q和isl封装，当使用802.1q时，对于本地VLAN不进行封

装，其他VLAN封装，ISL则全部封装。

2.VSPAN  
(1)创建VSPAN源VLAN  
monitor session session\_number source vlan vlan-id \[, | -] rx  
\*\*一样的也不说了，基本和SPAN相同，只是接口号变成了VLAN号，而且只能镜像接收的流量。  
(2)创建VSPAN目的端口  
monitor session session\_number destination interface interface-id \[encapsulation {dot1q | isl}]  
\*\*和SPAN的一样。

3.RSPAN  
RSPAN的配置较为复杂，其流程可以这样来看，交换机把要镜像的端口流量复制一份，然后发到本机的一个反射端口上（reflector-port ）

，在由反射端口将其通过网络转发到目的交换机中的VLAN上（一般情况下，这个VLAN是专为镜像而设的，不要作为客户端接入所用），再在目

的交换机中配置VSPAN，将该VLAN的流量镜像到目的端口，要注意的是，一旦这种RSPAN被使用，该镜像专用VLAN的信息会被转发到所有的VLAN

主干上，造成网络带宽的浪费，因此要配置VLAN修剪(pruning)，另外RSPAN也可以镜像VLAN。  
(1)在源交换机上创建RSPAN源端口  
\*\*同SPAN或VSPAN  
(2)在源交换机上创建VSPAN反射端口和目的VLAN  
monitor session session\_number destination remote vlan vlan-id reflector-port interface  
\*\*vlan-id 目的交换机上转为镜像而设的VLAN  
\*\*reflector-port interface源交换机上的镜像端口  
(3)在目的交换机上创建VSPAN源VLAN  
monitor session session\_number source remote vlan vlan-id  
\*\*vlan-id就是上面的镜像专用VLAN  
(4)在目的交换机上创建VSPAN目的端口  
monitor session session\_number destination interface interface-id \[encapsulation {dot1q | isl}]  
\*\*同SPAN

4.其他  
(1)端口镜像的过滤，端口镜像是可以做Filter的。  
monitor session session\_number filter vlan vlan-id \[, | -]  
\*\*指定源端口进入的流量中，属于哪些VLAN的可以从目的端口发出去。  
(2)删除镜像  
no monitor session {session\_number | all | local | remote}  
\*\*session\_number指定会话号，all是所有镜像，local是本地镜像，remote是远程镜像。  
(3)镜像的目的端口不能正常收发数据，因此不能再作为普通端口使用，可以连接一些网络分析和安全设备，例如装有sniifer的计算机或者Cisco IDS设备。