端口镜像是将指定端口(源端口)的报文复制一份到其它端口(目的端口),目的端口会与数据监测设备相连,用户利用这些数据监测设备来分析复制到目的端口的报文,进行网络监控和故障排除。常见的数据审计就通过端口镜像来获取数据的。
镜像的方向
端口镜像的方向分为三种:
入方向(inbound):仅对源端口接收的报文进行镜像
出方向(outbound):仅对源端口发送的报文进行镜像
双向(out):对源端口接收和发送的报文都进行镜像
镜像的分类
端口镜像分为两种:
本地端口镜像:是指将设备的一个或多个源端口的报文复制到本设备的一个目的端口,用于报文的监控和分析。其中,源端口和目的端口必须在同一台设备上。
远程端口镜像:除了可以实现本地端口镜像的功能外,它还突破了源端口和目的端口必须在同一台设备上的限制,使源端口和目的端口间可以跨越多个网络设备。目前,远程端口镜像功能可以穿越二层网络,但无法穿越三层网络。
0x01 本地镜像(多对一)
system-view
#配置镜像组
mirroring-group 1 local
#配置镜像源端口
mirroring-group 1 mirroring-port gigabitethernet 1/0/1 gigabitethernet 1/0/2 both
#配置镜像目的端口
mirroring-group 1 monitor-port gigabitethernet 1/0/3
#关闭目的端stp协议
interface ten-gigabitethernet 1/0/3
undo stp enable
#查看镜像组
display mirroring-group all
0x02 本地镜像(多对多)
通过反射的方式来实现,加入反射vlan的端口都能收到流量
system-view
#配置远程镜像组
mirroring-group 1 remote-source
#配置镜像源端口
mirroring-group 1 mirroring-port gigabitethernet 1/0/1 to gigabitethernet 1/0/3 both
#配置反射端口,此端口不能接线
mirroring-group 1 reflector-port gigabitethernet 1/0/28
#创建VLAN4091作为镜像组1的远程镜像VLAN,并将接镜像的目的端口划入改vlan
vlan 4091
port gigabitethernet 1/0/4 to gigabitethernet 1/0/5
#配置VLAN4091作为镜像组1的远程镜像VLAN
mirroring-group 1 remote-probe vlan 4091
#关闭目的端stp协议
interface ten-gigabitethernet 1/0/28
undo stp enable
#显示Device上所有镜像组的配置信息。
[Device] display mirroring-group all
Mirroring group 1:
Type: remote source
Status: Active
Mirroring port:
GigabitEthernet1/0/1 Both
GigabitEthernet1/0/2 Both
GigabitEthernet1/0/3 Both
Reflector port: GigabitEthernet1/0/28
Remote probe VLAN: 4091
0x03 远程镜像
接收设备配置
#创建远程目的镜像组1
mirroring-group 1 remote-destination
#创建VLAN 4091作为远程镜像VLAN
vlan 5
# 为远程目的镜像组1配置远程镜像VLAN为VLAN 5,及配置连接数据监测设备的端口Ten-GigabitEthernet 1/0/3为目的端口
mirroring-group 1 remote-probe vlan 4091
mirroring-group 1 monitor-port ten-gigabitethernet 1/0/3
# 将镜像目的端口加入远程镜像VLAN。将镜像数据发送给监测设备时,不需要携带远程镜像VLAN的VLAN Tag,因此将该端口配置为Access端口。
interface ten-gigabitethernet 1/0/3
port access vlan 4091
#关闭目的端口Ten-GigabitEthernet1/0/3上的生成树协议
undo stp enable
源设备配置
# 创建远程源镜像组1
mirroring-group 1 remote-source
#创建VLAN 4091作为远程镜像VLAN
vlan 4091
# 配置远程源镜像组1的远程镜像VLAN为VLAN 4091,对源端口Ten-GigabitEthernet1/0/1进行镜像,反射端口为Ten-GigabitEthernet1/0/5。
mirroring-group 1 remote-probe vlan 4091
mirroring-group 1 mirroring-port ten-gigabitethernet 1/0/1 both
mirroring-group 1 reflector-port ten-gigabitethernet 1/0/5