CISCO发现协议CDP详解

来源:百度文库 编辑:神马文学网 时间:2024/04/27 12:46:39

CISCO发现协议CDP详解

  CISCO发现协议(cisco discovery protocol)是由cisco设计的专用协议,能够帮助管理员收集关于本地连接和远程连接设备的相关信息。通过使用CDP可以收集相邻设备的硬件和协议信息,此信息对于故障诊断和网络文件归档非常有用。

  获取CDP定时器和保持时间信息

  通过打入SHOW CDP可以将显示两个全局参数的信息,这两个参数可以在CISCO的设备上进行配置。

  1.CDP定时器的意思指多长时间CDP会将分组传输到所有活动接口的时间量。(后有实验证明)

  2.CDP保持时间是指该信息将从已经接收到该信息的设备上存留多少时间。(后有实验证明)

  CISCO路由器和交换机都使用相同的参数。

  通过SHOW CDP命令默认在路由器上将显示如下内容。

  R1#show cdp

  Global CDP information:

  Sending CDP packets every 60 seconds

  Sending a holdtime value of 180 seconds

  在交换机上将显示如下内容。

  SW1#show cdp

  Global CDP information:

  Sending CDP packets every 60 seconds

  Sending a holdtime value of 180 seconds

  Sending CDPv2 advertisements is enabled

  可见默认情况下路由器发送V1版本的CDP信息,而交换机默认发送V2版本的CDP信息。

  这两条输出信息分别代表的含义为:

  Sending CDP packets every 60 seconds

  每60秒发送一次CDP更新信息包。

  Sending a holdtime value of 180 seconds

  此信息保持时间为180秒。

  修改CDP定时器与保持时间信息。

  在全局模式下使用命令CDP TIMER和CDP HOLDTIME在路由器上配置CDP定时器和保持时间。

  SW1#conf t

  Enter configuration commands, one per line. End with CNTL/Z.

  SW1(config)#cdp ?

  advertise-v2 CDP sends version-2 advertisements

  holdtime      Specify the holdtime (in sec) to be sent in packets

  timer         Specify the rate at which CDP packets are sent       (in sec)

  run

  SW1(config)#cdp timer 90

  SW1(config)#cdp holdtime 240

  SW1(config)#

  SW1#show

  00:15:39: %SYS-5-CONFIG_I: Configured from console by console

  SW1#show cdp

  Global CDP information:

  Sending CDP packets every 90 seconds

  Sending a holdtime value of 240 seconds

  Sending CDPv2 advertisements is enabled

  启动与关闭CDP

  在路由器的全局配置模式下可以使用NO CDP RUN命令完全的关闭CDP。若要在路由器接口上关闭或打开CDP,使用NO CDP ENABLE和CDP ENABLE命令。

  收集邻居信息

  Show cdp neighbor命令可以显示有关直连设备的信息。要记住CDP分组不经过CISCO交换机这非常重要,它只能看到与它直接相连的设备。在连接到交换机的路由器上,不会看到连接到交换机上的其他所有设备。如下配置。

  (图一)

  R1分别与R2和SW1直连,此时我们在R1上使用show cdp neighbor命令后的输出为如下所显示。

  R1#show cdp nei

  Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge

  S - Switch, H - Host, I - IGMP, r - Repeater

  Device ID        Local Intrfce     Holdtme    Capability Platform Port ID

  SW1                 Eth 0          154          T S       WS-C2912-XFas 0/1

  R2                  Ser 0          161           R        2500      Ser 0

  R1#

  如实验结果所示,路由器R1只显示出与它直连的路由器R2和交换机SW1,而不会显示与交换机SW1直接相连的R3的路由信息。

  下面列出show cdp neighbor命令为每个设备显示的信息。

  Device ID: 直连设备的主机名

  Local interface :要接收CDP分组的端口或接口(直接控制的本地设备)

  Holdtime :如果没有接收到其他CDP分组,路由器在丢弃接收到的信息之前将要保存的时间量。

  Capability :邻居设备的类型,如路由器,交换机或中继器。

  Platform :CISCO设备类型在上面的输出中cisco 2500和catalyst 2912是直连在路由器R1上的设备。

  Port ID :与路由器R1直接相连的设备在发送更新时所用的接口。

  另一个提供相邻设备信息的命令为show cdp neighbor命令,此命令可以在路由器或交换机上运行,它显示连接到此设备上的每个设备的详细信息,下面为命令输出的例子。

  R1#show cdp neighbor detail

  -------------------------

  Device ID: SW1

  Entry address(es):

  IP address: 50.50.50.1

  Platform: cisco WS-C2912-XL, Capabilities: Trans-Bridge Switch

  Interface: Ethernet0, Port ID (outgoing port): FastEthernet0/1

  Holdtime : 239 sec

  Version :

  Cisco Internetwork Operating System Software

  IOS (tm) C2900XL Software (C2900XL-C3H2S-M), Version 12.0(5)WC14, RELEASE SOFTWARE (fc1)

  Copyright (c) 1986-2006 by cisco Systems, Inc.

  Compiled Thu 16-Feb-06 14:39 by antonino

  -------------------------

  Device ID: R2

  Entry address(es):

  IP address: 10.10.10.2

  Platform: cisco 2500, Capabilities: Router

  Interface: Serial0, Port ID (outgoing port): Serial0

  Holdtime : 126 sec

  Version :

  --More--

  CDP-EV: Bad version number in header

  CDP-PA: Packet received from SW1 on interface Ethernet0

  **Entry found in cache**

  Cisco Internetwork Operating System Software

  IOS (tm) 3000 Software (IGS-I-L), Version 11.0(3), RELEASE SOFTWARE (fc1)

  Copyright (c) 1986-1995 by cisco Systems, Inc.

  Compiled Tue 07-Nov-95 15:04 by deannaw

  R1#

  通过这条命令给出了直连设备的主机名、相关型号、类型、本地发出更新的接口和对方接收CDP更新信息的接口,保持时间以及IOS的版本号等。

  说明:你只能看到直连设备的IP地址。

  Show cdp entry *命令与show cdp neighbor details命令所显示的为相同的信息。下面是show cdp entry *命令的路由器输出的例子。

  R1#show cdp entry *

  -------------------------

  Device ID: SW1

  Entry address(es):

  IP address: 50.50.50.1

  Platform: cisco WS-C2912-XL, Capabilities: Trans-Bridge Switch

  Interface: Ethernet0, Port ID (outgoing port): FastEthernet0/1

  Holdtime : 204 sec

  Version :

  Cisco Internetwork Operating System Software

  IOS (tm) C2900XL Software (C2900XL-C3H2S-M), Version 12.0(5)WC14, RELEASE SOFTWARE (fc1)

  Copyright (c) 1986-2006 by cisco Systems, Inc.

  Compiled Thu 16-Feb-06 14:39 by antonino-------------------------

  Device ID: R2

  Entry address(es):

  IP address: 10.10.10.2

  Platform: cisco 2500, Capabilities: Router

  Interface: Serial0, Port ID (outgoing port): Serial0

  Holdtime : 121 sec

  Version :

  Cisco Internetwork Operating System Software

  IOS (tm) 3000 Software (IGS-I-L), Version 11.0(3), RELEASE SOFTWARE (fc1)

  Copyright (c) 1986-1995 by cisco Systems, Inc.

  Compiled Tue 07-Nov-95 15:04 by deannaw

  R1#

  收集接口流量信息。

  Show cdp traffic命令显示接口流量的信息,包括发送和接收CDP分组的数量,以及CDP出错信息。

  下面显示的是在路由器上使用show cdp traffic命令后的输出结果。

  R1#show cdp traffic

  CDP counters :

  Packets output: 750, Input: 626

  Hdr syntax: 212, Chksum error: 0, Encaps failed: 0

  No memory: 0, Invalid packet: 0, Fragmented: 0

  R1#

  这并非是路由器上可以收集到的最重要的信息,但是它显示了设备发送和接收的CDP分组数。

  以上路由期发送了750个CDP组播数据包,接收了626个组播数据包,封装失败、错误、无效以及碎片包裹均为0。

  收集端口和接口信息

  Show cdp interface命令可显示路由器接口或者交换机、路由器端口的状态。

  可以通过使用no cdp run命令完全关闭路由器上的所有CDP。CDP也可以用no cdp enable命令关闭单个接口的CDP,如果要打开相应端口的cdp可以使用cdp enable命令启用端口。在默认的情况下,所有的端口默认为cdp enable即启动状态。

  使用show cdp interface命令可以显示每个接口的cdp信息,包括每个接口的线路封装类型,定时器和保持时间。

  下面列举show cdp interface所显示的信息。

  R1#show cdp interface

  Ethernet0 is up, line protocol is up, encapsulation is ARPA

  Sending CDP packets every 60 seconds

  Holdtime is 180 seconds

  Serial0 is up, line protocol is up, encapsulation is HDLC

  Sending CDP packets every 60 seconds

  Holdtime is 180 seconds

  Serial1 is administratively down, line protocol is down, encapsulation is HDLC

  Sending CDP packets every 60 seconds

  Holdtime is 180 seconds

  R1#

  从以上实验调试结果可看到E0接口与S0接口状态为UP,而S1接口的状态为administratively down,但是此时CDP仍然在所有接口运行。

  若要关闭路由器上的一个接口的CDP,可在接口模式下使用no cdp enable命令。

  如下所示

  R1#conf t

  Enter configuration commands, one per line. End with CNTL/Z.

  R1(config)#int e 0

  R1(config-if)#no cdp enable

  R1(config-if)#end

  使用show cdp interface验证所做的修改。

  R1#show cdp interface

  Serial0 is up, line protocol is up, encapsulation is HDLC

  Sending CDP packets every 60 seconds

  Holdtime is 180 seconds

  Serial1 is administratively down, line protocol is down, encapsulation is HDLC

  Sending CDP packets every 60 seconds

  Holdtime is 180 seconds

  R1#

  注意!上面路由器在输出中没有列出接口E0,说明此时已经成功关闭了E0接口的CDP功能。要想重新启动E0接口的 CDP功能可在E0接口上运行命令cdp enable,此时E0口的CDP功能将得到重新恢复。

  如下调试结果。

  R1#conf t

  Enter configuration commands, one per line. End with CNTL/Z.

  R1(config)#int e 0

  R1(config-if)#cdp enable

  R1(config-if)#exi

  R1(config)#exi

  R1#show interfa

  %SYS-5-CONFIG_I: Configured from console by console

  R1#show cdp interface

  Ethernet0 is up, line protocol is up, encapsulation is ARPA

  Sending CDP packets every 60 seconds

  Holdtime is 180 seconds

  Serial0 is up, line protocol is up, encapsulation is HDLC

  Sending CDP packets every 60 seconds

  Holdtime is 180 seconds

  Serial1 is administratively down, line protocol is down, encapsulation is HDLC

  Sending CDP packets every 60 seconds

  Holdtime is 180 seconds

  R1#

  保持时间是如何计时与清除超时信息的。

  我们知道CDP过了保持时间以后会自动被清除,那么保持时间是如何被清除的可见如下实验。

  首先我们先到交换机SW1上去关闭交换机与路由器R1的直连端口fastethernet 0/1

  SW1#conf t

  Enter configuration commands, one per line. End with CNTL/Z.

  SW1(config)#int fa 0/1

  SW1(config-if)#no cdp enable

  SW1(config-if)#exi

  SW1(config)#

  然后我们到路由器R1上查看保持时间。

  R1#show cdp nei

  Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge

  S - Switch, H - Host, I - IGMP, r - Repeater

  Device ID        Local Intrfce     Holdtme    Capability Platform Port ID

  SW1                 Eth 0          6            T S       WS-C2912-XFas 0/1

  R2                  Ser 0          136           R        2500      Ser 0

  R1#show cdp nei

  Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge

  S - Switch, H - Host, I - IGMP, r - Repeater

  Device ID        Local Intrfce     Holdtme    Capability Platform Port ID

  SW1                 Eth 0          0            T S       WS-C2912-XFas 0/1

  R2                  Ser 0          130           R        2500      Ser 0

  R1#show cdp nei

  Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge

  S - Switch, H - Host, I - IGMP, r - Repeater

  Device ID        Local Intrfce     Holdtme    Capability Platform Port ID

  R2                  Ser 0          126           R        2500      Ser 0

  R1#

  我们可以从中看到SW1保持时间的变化规律,连续的三个show cdp neighbor命令,看到保持时间是逐步递减的,一直减到0,1秒不差。然后从列表中消失。

  如何查看单台直连设备的CDP信息。

  我们可以通过如下两条命令来查看领接设备的相应信息。如R1直连R2,从R1上打入命令:

  Show cdp entry R2 pro与show cdp entry R2 ver 分别可以查看设备R2的协议与IOS版本信息,实验步骤与调试如下:

  注意:HOSTNAME主机名需区大小写。

  R1#show cdp entry R2 pro

  R1#show cdp entry R2 protocol

  Protocol information for R2 :

  IP address: 10.10.10.2

  R1#show cdp entry R2 ver

  R1#show cdp entry R2 version

  Version information for R2 :

  Cisco Internetwork Operating System Software

  IOS (tm) 3000 Software (IGS-I-L), Version 11.0(3), RELEASE SOFTWARE (fc1)

  Copyright (c) 1986-1995 by cisco Systems, Inc.

  Compiled Tue 07-Nov-95 15:04 by deannaw