SPAN那些事

1.SPAN概述
SPAN(Switched Port Analyzer)就是我们常说的端口镜像技术,当网络管理源需要分析设备端口上流入或流出数据时,就可以利用SPAN技术来复制到IPS等分析器。
SPAN可以从一个或多个端口、EtherChannels、vlan完整复制一份数据流到目的网络分析器。SPAN不会影响现有业务数据交互,但必须预留目的端口(不能用于传输业务);
SPAN可以分为3种类型:Local SPAN、Remote SPAN、Encapsulation Remote SPAN。
- Local SPAN:由源端口或源vlan和目的端口组成,且只能应用在单台switch上(源端口和源vlan不能同时配置);
- RSPAN:由源地址或源VLAN、remote vlan、目标端口组成,可以横跨二层多台交换机,主要由remote vlan要传输流量(源端口和源vlan不能同时配置);
-
ERSPAN:由源端口或源vlan和目标端口组成,通过GRE封装,可以横过三层网络(源端口和源vlan不能同时配置);
image
关于镜像源:
-
可以镜像入向ingress(rx)或出向egress(tx)或两者流量;
-
缺省情况下,local SPAN和ERSPAN可以监控所有流量包含组播和BPDU,RSPAN则不支持BPDU;
-
可以镜像CPUs、端口/聚合口、VLAN作为镜像源;
关于镜像目的:
-
聚合端口不支持PAgP或LACP,仅支持ON模式;
-
默认情况下目的端口不传输任何数据流量;
2.Local SPAN约束与配置
常用部分配置
#全局配置模式:
monitor session 1 source interface Et0/0 //指定源端口
monitor session 1 filter vlan 1 , 2 //指定过滤vlan,可选
monitor session 1 destination interface Et0/1 //指定目的端口
#SPAN配置模式:
monitor session 1 type local
source interface Et0/0 //指定源端口
filter 1 , 2 //指定过滤vlan,可选
destination interface Et0/1 //指定目的端口
no shutdown //SPAN配置模式下一定要no shutdown
说明:针对高版本可以支持source可以带CPU/SP/RP
高级部分配置
#抓trunk流量,需要dot1q封装
monitor session 1 source interface Et0/0
monitor session 1 destination interface Et0/1 encapsulation replicate
#抓vlan流量,并且通过dot1q来区分vlan
monitor session 1 source vlan 1,2,3 rx
monitor session 1 destination interface Et0/1 encapsulation dot1q
#使用ingress注入数据
monitor session 1 source vlan 1,2,3 rx
monitor session 1 destination interface Et0/1 encapsulation dot1q ingress dot1q vlan 1 //dot1q 1为native vlan
3.RSPAN约束与配置
-
所有参与的交换机必须是二层trunk连接;
-
任何网络设备能够支持RSPAN VLAN都可以作为中间设备;
-
对在网络上传输的RSPAN VLAN数量没有限制;
-
中间网络设备可能会对支持RSPAN VLAN的数量上做限制;
-
从源交换机、中间设备、目的交换机上都必须配置RSPAN VLAN;
-
如果启用VTP及VTP修剪,在trunk链路上修剪RSPAN VLAN流量预防不必要的泛洪;
-
RSPAN VLAN仅被用作RSPAN镜像流量;
-
不要用承载管理流量的VLAN用作RSPAN VLAN;
-
不能将物理口划分至RSPAN VLAN,否则该接口不可用,除了trunk接口;
-
RSPAN VLAN会关闭MAC地址学习功能;
-
可以在源交换机上对RSPAN VLAN出方向应用ACL来过滤去往目标端口的流量;
-
RSPAN不支持监控BPDU;
-
不能够将RSPAN VLAN作为镜像源会话;
-
在所有设备能够支持RSPAN VLAN上可以使用任何VLAN作为RSPAN VLAN;
#以下演示全局配置模式:
#源交换机
vlan 100 //每台交换机都要创建RSPAN VLAN
remote-span
monitor session 1 source interface Et0/0
monitor session 1 destination remote vlan 100
#中间交换机(如源、目的直连则跳过此步骤)
vlan 100 //每台交换机都要创建RSPAN VLAN
remote-span
monitor session 1 destination remote vlan 100
#目标交换机
vlan 100 //每台交换机都要创建RSPAN VLAN
remote-span
monitor session 1 source remote vlan 100
monitor session 1 destination interface ethernet 0/2
4.ERSPAN约束与配置
-
在ERSPAN数据包里针对GRE特殊protocol type字段为"0x88BE"(RFC定义的为0x0800);
-
将二层帧封装在三层ERSPAN包中;
-
ERSPAN最大支持9202字节包含三层数据包;
-
结果某接口强制MTU小于9202字节可能会丢弃ERSPAN数据包;
-
参与ERSPAN交换机必须基于三层网络连接且能够承载ERSPAN流量大小;
-
ERSPAN不支持数据包分片和重组装;
-
ERSPAN支持设置IP优先级和DSCP值提供QoS服务;
-
交换机上的ERSPAN源会话必须使用同一个origin IP地址(即源IP地址);
-
交换机上的ERSPAN目标会话在相同目标接口必须使用同IP地址(即目标出口一样source IP一致);
-
ERSPAN源会话里的目标IP与目标会话里的源IP要一直(即源会话的destination ip与目标会话的source ip);
-
ERSPAN源会话与目标会话里的ERSPAN-ID要一致;
#源路由器
monitor session 1 type erspan-source
source interface e0/0
no shutdown
destination
erspan-id 101 //erspan-id 源和目的要一致,标识同隧道
ip address 2.2.2.2 //指定目的交换机IP
origin ip address 1.1.1.1 //指定源交换机IP
#目标路由器
monitor session 1 type erspan-destination
destination interface e0/2 //指定目的交换机端口
no shutdown
source
erspan-id 101 //erspan-id 源和目的要一致,标识同隧道
ip address 2.2.2.2 //指定目的交换机IP
5.验证命令
show monitor session all //查看所有会话
show monitor session <id> //单独查看某个会话
show monitor session <id> detail //详细查看某个会话