mahonglin123456 发表于 2017-7-9 11:09:04

[转载]抓包,端口镜像,monitor session命令(转)

原文地址:抓包,端口镜像,monitor session命令(转)作者:浮云皓月
  一、SPAN简介
  SPAN技术主要是用来监控交换机上的数据流,大体分为两种类型,本地SPAN和远程SPAN.
  —-Local Switched Port Analyzer (SPAN) and Remote SPAN(RSPAN),实现方法上稍有不同。
  利用SPAN技术我们可以把交换机上某些想要被监控端口(以下简称受控端口)的数据流COPY或MIRROR一份,发送给连接在监控端口上的流量分析仪,比如CISCO的IDS或是装了SNIFFER工具的PC.受控端口和监控端口可以在同一台交换机上(本地SPAN),也可以在不同的交换机上(远程SPAN)。
  二、名词解释
  SPAN Session——SPAN会话
  SPAN会话是指一组受控端口与一个监控端口之间的数据流。可以同时对多个端口的进入流量或是一个端口的外出流量进行监控,也可以对VLAN内所有端口的进入流量进行监控,但不能同时对多个端口的外出流量及VLAN的外出流量进行监控,可以对处于关闭状态的端口设置SPAN,但此时的SPAN会话是非活动,但只要相关的接口被打开,SPAN就会变为活动的。
  监控端口最好是>=受控端口的带宽,否则可能会出现丢包的情况。
  SPAN Traffic——SPAN的流量
  使用本地SPAN可以监控所有的网络流量,包括multicast、bridge protocol data unit(BPDU),和CDP、VTP、DTP、STP、PagP、LACP packets. RSPAN不能监控二层协议。
  Traffic Types——流量类型
  被监控的流量类型分为三种,Receive (Rx) SPAN 受控端口的接收流量,Transmit (Tx) SPAN受控端口的发送流量,Both 一个受控端口的接收和发送流量。
  Source Port——SPAN会话的源端口(也就是monitored port-即受控端口)
  受控端口可以是实际的物理端口、VLAN、以太通道端口组EtherChannel,物理端口可以在不同的VLAN中,受控端口如果是VLAN则包括此VLAN中的所以物理端口,受控端口如果是以太通道则包括组成此以太通道组的所有物理端口,如果受控端口是一个TRUNK干道端口,则此TRUNK端口上承载的所有VLAN流量都会受到监控,也可以使用filter vlan 参数进行调整,只对filter vlan中指定的VLAN数据流量做监控。
  Destination Port——SPAN会话的目的端口(也就是monitoring port-即监控端口)
  监控端口只能是单独的一个实际物理端口,一个监控端口同时只能在一个SPAN会话中使用,监控端口不参与其它的二层协议如:
  Layer 2 protocols
  Cisco Discovery Protocol (CDP),
  VLAN Trunk Protocol (VTP),
  Dynamic Trunking Protocol (DTP),
  Spanning Tree Protocol (STP),
  Port Aggregation Protocol (PagP),
  Link Aggregation Control Protocol (LACP)。
  缺省情况下监控端口不会转发除SPANSession以外的任何其它的数据流,也可以通过设置ingress参数,打开监控端口的二层转发功能,比如当连接CISCOIDS的时会有这种需求,此时IDS不仅要接收SPANSession的数据流,IDS本身在网络中还会与其它设备有通讯流量,所以要打开监控端口的二层转发功能.
  Reflector Port——反射端口
  反射端口只在RSPAN中使用,与RSPAN中的受控端口在同一台交换机上,是用来将本地的受控端口流量转发到RSPAN中在另一台交换机上的远程监控端口的方法,反射端口也只能是一个实际的物理端口,它不属于任何VLAN(It is invisible to allVLANs.)。
  RSPAN中还要使用一个专用的VLAN来转发流量,反射端口会使用这个专用VLAN将数据流通过TRUNK端口发送给其它的交换机,远程交换机再通过此专用VLAN将数据流发送到监控端口上的分析仪。
  关于RSPAN VLAN的创建,所有参与RSPAN的交换机应在同一个VTP域中,不能用VLAN1,也不能用1002-1005,这是保留的(reserved for Token Ring and FDDIVLANs),如果是2-1001的标准VLAN,则只要在VTPServer上创建即可,其它的交换机会自动学到,如果是1006-4094的扩展VLAN,则需要在所有交换机上创建此专用VLAN.
  反射端口最好是>=受控端口的带宽,否则可能会出现丢包的情况。
  VLAN-Based SPAN——基于VLAN的SPAN
  基于VLAN的SPAN只能监控VLAN中所有活动端口接收的流量(only received (Rx)traffic),如果监控端口属于此VLAN,则此端口不在监控范围内,VSPAN只监控进入交换机的流量,不对VLAN接口上的路由数据做监控。
  (VSPAN only monitors traffic that enters the switch, not trafficthat is routed between VLANs. For example, if a VLAN is beingRx-monitored and the multilayer switch routes traffic from anotherVLAN to the monitored VLAN, that traffic is not monitored and isnot received on the SPAN destination port. )
  三、SPAN和RSPAN与其它特性的互操作性
  Routing——SPAN不监控VLAN间的路由数据;(不好理解)
  Routing—Ingress SPAN does not monitor routed traffic. VSPAN onlymonitors traffic that enters the switch, not traffic that is routedbetween VLANs. For example, if a VLAN is being Rx-monitored and themultilayer switch routes traffic from another VLAN to the monitoredVLAN, that traffic is not monitored and not received on the SPANdestination port.
  STP——监控端口和反射端口不会参与STP,但SPAN对受控端口的STP没有影响;
  CDP——监控端口不参与CDP;
  VTP——RSPAN VLAN可以被修剪pruning;
  VLAN andtrunking——可以修改受控端口、监控端口和反射端口的VLAN和TRUNK设置,受控端口的改变会立即生效,而监控端口和反射端口则要在从SPAN中去除后才会生效;
  EtherChannel——整个以太通道组可以做为受控端口使用,如果一个属于某个以太通道组的物理端口被配成了受控端口、监控端口或反射端口,则此端口会自动从以太通道组去除,当SPAN删除后,它又会自动加入原以太通道组;
  QoS——由于受QoS的策略影响,监控端口上收到的数据流会与受控端口实际的数据流不同,比如DSCP值被修改等;
  Multicast——SPAN可以监控组播的数据流;
  Port security——安全端口不能做为监控端口使用;
  802.1x——受控端口、监控端口和反射端口上可以设置802.1x,但有些限制。
  四、SPAN和RSPAN的配置举例
  SPAN的限制和缺省设置
  Catalyst 3550交换机上最多只能设置两个SPANSession,缺省SPAN没有使用,如果做了设置,缺省情况下,第一个被设为受控端口的接口进出流量都会受到监控,以后再追加的受控端口只会对接收的流量进行监控,监控端口的默认封装类型为Native,也就是没有打VLAN的标记.
  1、Configuring SPAN——配置本地SPAN
  Switch(config)# no monitor session 1 //先清除可能已经存在SPAN设置
  Switch(config)# monitor session 1 source interfacefastethernet0/10//设定SPAN的受控端口
  Switch(config)# monitor session 1 destination interfacefastethernet0/20 //设定SPAN的监控端口
  Switch#sh mon
  Session 1
  ---------
  Type : Local Session
  Source Ports : Both : Fa0/10 //注意此处是Both
  Destination Ports : Fa0/20
  Encapsulation : Native
  Ingress: Disabled
  Switch(config)# monitor session 1 source interfacefastethernet0/11 - 13 //添加SPAN的受控端口
  Switch#sh mon
  Session 1
  ---------
  Type : Local Session
  Source Ports : RX Only : Fa0/11-13 //注意此处是
  RX OnlyBoth : Fa0/10 //注意此处还是Both
  Destination Ports : Fa0/20
  Encapsulation : Native
  Ingress: Disabled
  Switch(config)# monitor session 1 destination interface fa0/20ingress vlan 5 //设定SPAN的监控端口并启用二层转发
  Switch#sh mon
  Session 1
  ---------
  Type : Local Session
  Source Ports :
  RX Only : Fa0/11-13
  Both : Fa0/10
  Destination Ports : Fa0/20
  Encapsulation : Native
  Ingress: Enabled, default VLAN = 5 //允许正常的流量进入 Ingressencapsulation: Native
2、Specifying VLANs to Filter  Switch(config)# no monitor session 2
  Switch(config)# monitor session 2 source vlan 101 - 102 rx
  Switch(config)# monitor session 2 destination interfacefastethernet0/30
  Switch#sh mon ses 2
  Session 2
  ---------
  Type : Local Session
  Source VLANs : RX Only : 101-102 //注意此处是RX Only
  Destination Ports : Fa0/30
  Encapsulation : Native
  Ingress: Disabled
  Switch(config)# monitor session 2 source vlan 201 - 202 rx
  Switch#sh mo se 2
  Session 2
  ---------
  Type : Local Session
  Source VLANs : RX Only : 101-102,201-202 //注意此处多了201-202
  Destination Ports : Fa0/30
  Encapsulation : Native
  Ingress: Disabled
3、Configuring RSPAN——配置远程RSPAN  RSPAN的Session分成RSPAN Source Session和RSPAN DestinationSession两部分,所以相应的配置也要分别在Session的源和目的交换机上做。
  3.1、首先要配置专用的RSPAN VLAN
  Switch(config)# no monitor session 2
  Switch(config)# monitor session 2 source interfacefastethernet0/48 rx
  Switch(config)# monitor session 2 filter vlan 100 - 102//指定受控的VLAN范围
  Switch(config)# monitor session 2 destination interfacefastethernet0/30
  Switch#sh mon ses 2
  Session 2
  ---------
  Type : Local Session
  Source Ports : Both : Fa0/48
  Destination Ports : Fa0/30
  Encapsulation : Native
  Ingress: Disabled
  Filter VLANs : 100-102 //只监控VLAN100-102中的流量
  3.2、配置RSPAN Source Session
  Switch(config)# vlan 800
  Switch(config-vlan)# remote-span
  Switch(config-vlan)# end
  sw1#sh vl id 800
  VLAN Name Status Ports
  ---- --------------------------------
  800 VLAN0800 active Fa0/47, Fa0/48
  VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1Trans2
  ---- ----- ---------- ----- ------
  800 enet 100800 1500 - - - - - 0 0
  Remote SPAN VLAN
  ----------------
  Enabled //注意看此处的提示
  Primary Secondary Type Ports
  ------- --------- -----------------
  3.3、配置RSPAN Destination Session
  Switch(config)# no monitor session 1
  Switch(config)# monitor session 1 source interfacefastethernet0/10 - 13
  Switch(config)# monitor session 1 source interfacefastethernet0/15 rx
  Switch(config)# monitor session 1 destina remote vlan 800reflector-port fa0/20
  sw1#sh mo se 1
  Session 1
  ---------
  Type : Remote Source Session
  Source Ports :
  RX Only : Fa0/11-13,Fa0/15
  Both : Fa0/10
  Reflector Port : Fa0/20
  Dest RSPAN VLAN : 800
  (VLAN-BasedRSPAN)基于VLAN的RSPAN也和上面的方法类似,只不过受控的是整个VLAN.启用监控端口的二层转发以及Specifying  VLANs to Filter 的方法也和本地SPAN相同,此处不再举例。详见CISCO CD.
This example shows how to configure SPAN so that both the transmitand receive
traffic from port 2/4 (the SPAN source) is mirrored on port 3/6(the SPAN destination):
Console> (enable) set span 2/4 3/6
// Overwrote Port 3/6 to monitor transmit/receive traffic of Port2/4
Incoming Packets disabled. Learning enabled.
Console> (enable) show span
Destination : Port 3/6
Admin Source : Port 2/4
Oper Source : None
Direction : transmit/receive
Incoming Packets: disabled
Learning : enabled
Filter : -
Status : active
———————————————-
Total local span sessions: 1
Console> (enable)
This example shows how to set VLAN 522 as the SPAN source and port2/1 as the SPAN destination:
Console> (enable) set span 522 2/1
// Overwrote Port 2/1 to monitor transmit/receive traffic of VLAN522
Incoming Packets disabled. Learning enabled.
Console> (enable) show span
Destination : Port 2/1
Admin Source : VLAN 522
  你得在交换机上做一个端口镜像,让其它端口的数据都复制一份到你所接入的这个端口上来,用sniffer软件就可以了,但你所在的这个端口只能做管理接口使用,别的就什么都不能做了。命令:
  SW-3L(config)#monitor session 1 source int f0/1 both所要抓的包所在的端口
  SW-3L(config)#monitor session 1 destination int f0/24你的机器连接的端口
页: [1]
查看完整版本: [转载]抓包,端口镜像,monitor session命令(转)