SPAN,全称为Switched Port Analyzer,直译为交换端口分析器。是一种交换机的端口镜像技术。作用主要是为了给某种网络分析器提供网络数据流,SPAN并不会影响源端口的数据交换,它只是将源端口发送或接收的数据包副本发送到监控端口。
有hub连接的主机由于处在同一个广播域和冲突域,一个端口所发送的数据,会发往所有的端口,这样我们只要连接上hub,就可以监听连接在hub上的所有流量:
![notion image](https://www.notion.so/image/https%3A%2F%2Fs2.loli.net%2F2022%2F05%2F16%2Fc7kjpWCUBMqP5go.png?table=block&id=8e3488cb-0e04-4e9c-8e36-fd75dd6032ba&cache=v2)
交换机和hub不一样,交换机是通过MAC地址表来转发数据的,不存在hub的情况,但是如果想要分析局域网中的流量就会造成不便,由此产生了SPAN协议:
在交换机配置SPAN协议之前,sniffer即使连接上交换机也无法捕捉到流量:
![notion image](https://www.notion.so/image/https%3A%2F%2Fs2.loli.net%2F2022%2F05%2F16%2Fu2A5OTYPe43taEJ.png?table=block&id=5a9ed147-2661-4cc4-96b6-41c725157f5f&cache=v2)
交换机配置SPAN协议,把从f0/1端口发出的数据包复制一份发送到f0/3端口,这样sniffer自然就可以捕捉到数据包:
Switch(config)#monitor session 1 source f0/1 ? % Unrecognized command Switch(config)#monitor session 1 source int f0/1 ? , comma - hyphen both SPAN copies both egress and ingress traffic #复制入口和出口的流量 rx SPAN copies only ingress traffic #仅复制入口的流量 tx SPAN copies only egress traffic #仅复制出口的流量 <cr> Switch(config)#monitor session 1 source int f0/1 both #设置从f0/1端口发送和接收的数据包发送到f0/3端口 Switch(config)#mo Switch(config)#monitor se Switch(config)#monitor session 1 de Switch(config)#monitor session 1 destination int f0/3 ? , comma - hyphen <cr> Switch(config)#monitor session 1 destination int f0/3
sniffer已经可以捕捉到从PC0发送到PC1的ICMP数据包:
![notion image](https://www.notion.so/image/https%3A%2F%2Fs2.loli.net%2F2022%2F05%2F16%2FVk6jJwLiI7Y9lar.png?table=block&id=3fb4ded5-5d23-481f-8f5f-5ce20e403d87&cache=v2)