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 &#118alue of 180 seconds
在交换机上将显示如下内容。
SW1#show cdp
Global CDP information:
Sending CDP packets every 60 seconds
Sending a holdtime &#118alue of 180 seconds
Sending CDPv2 advertisements is enabled
可见默认情况下路由器发送V1版本的CDP信息,而交换机默认发送V2版本的CDP信息。
这两条输出信息分别代表的含义为:
Sending CDP packets every 60 seconds
每60秒发送一次CDP更新信息包。
Sending a holdtime &#118alue 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 &#118alue 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
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的路由信息。
Local interface :要接收CDP分组的端口或接口(直接控制的本地设备)
Holdtime :如果没有接收到其他CDP分组,路由器在丢弃接收到的信息之前将要保存的时间量。
Capability :邻居设备的类型,如路由器,交换机或中继器。
Platform :CISCO设备类型在上面的输出中cisco 2500和catalyst 2912是直连在路由器R1上的设备。
Port ID :与路由器R1直接相连的设备在发送更新时所用的接口。
-------------------------
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
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
--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#
-------------------------
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
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
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 counters :
Packets output: 750, Input: 626
Hdr syntax: 212, Chksum error: 0, Encaps failed: 0
No memory: 0, Invalid packet: 0, Fragmented: 0
R1#
以上路由期发送了750个CDP组播数据包,接收了626个组播数据包,封装失败、错误、无效以及碎片包裹均为0。
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#
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
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#
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#
首先我们先到交换机SW1上去关闭交换机与路由器R1的直连端口fastethernet 0/1
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)#
Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
S - Switch, H - Host, I - IGMP, r - Repeater
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
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
R2 Ser 0 126 R 2500 Ser 0
R1#
Show cdp entry R2 pro与show cdp entry R2 ver 分别可以查看设备R2的协议与IOS版本信息,实验步骤与调试如下:
注意:HOSTNAME主机名需区大小写。
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
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#
R1#debug cdp packets
CDP packet info debugging is on
R1#
CDP-PA: Packet received from R2 on interface Serial0
**Entry found in cache**
R1#
CDP-PA: Packet sent out on Ethernet0
CDP-PA: Packet sent out on Serial0
R1#
CDP-PA: Packet received from R2 on interface Serial0
**Entry found in cache**
R1#
CDP-PA: Packet sent out on Ethernet0
CDP-PA: Packet sent out on Serial0
R1#
CDP packet info debugging is off
R1#
CDP events debugging is on
