Using the Cisco Discovery Protocol

Using the Cisco Discovery Protocol

Problem

You want to see summary information about what is connected to your router's interfaces.

Solution

You can selectively enable or disable Cisco Discovery Protocol (CDP) on the entire router, or on individual interfaces:

Router1#configure terminal 
Enter configuration commands, one per line. End with CNTL/Z.
Router1(config)#cdp run
Router1(config)#interface Serial0/0
Router1(config-if)#cdp enable
Router1(config-if)#exit
Router1(config)#interface FastEthernet0/0
Router1(config-if)#no cdp enable
Router1(config-if)#exit
Router1(config)#interface FastEthernet1/0
Router1(config-if)#cdp enable
Router1(config-if)#end
Router1#

Discussion

CDP is enabled by default on the router, and on all interfaces. If you have previously disabled it, as discussed in Recipe 2.6, and you want to re-enable CDP on the router, you can issue the cdp run global configuration command:

Router1(config)#cdp run

This turns on CDP processing on all supported interfaces by default. If you don't want to run CDP on a particular interface, you can use the no cdp enable command, as we did for the serial interface in the example:

Router1(config)#interface Serial0/0
Router1(config-if)#no cdp enable

CDP is a Cisco proprietary protocol that allows Cisco devices to identify one another and exchange useful identifying information. The show cdp neighbors command gives a summary of information about adjacent devices that also happen to be running CDP:

Router1#show cdp neighbors 
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
Router2 Ser 0/0 179 R 2621 Ser 0/1
Switch1 Fas 1/0 152 T S WS-C2924 2/2
Router1#

As you can see, this output tells you the name and type of device of each neighbor, including the model number. It also includes both the interface on this router that connects to each neighbor and the corresponding interface on the neighbor device.

Notice that the last of the devices listed is actually a Cisco Catalyst Ethernet switch. This switch points out one of the most useful features of CDP. While other mechanisms such as the ARP cache, routing protocols, or even simple PING tests can tell you things about the Layer 3 neighbors, CDP gives you information about the Layer 2 neighbors. This is true even when the Layer 2 neighbor does not have an IP addresses configured.

You can see additional information about these neighboring devices by adding the detail keyword:

Router1#show cdp neighbors detail
-------------------------
Device ID: Router2
Entry address(es):
IP address: 10.1.1.2
Platform: cisco 2621, Capabilities: Router
Interface: Serial0/0, Port ID (outgoing port): Serial0/1
Holdtime : 136 sec

Version :
Cisco Internetwork Operating System Software
IOS (tm) C2600 Software (C2600-IK9O3S-M), Version 12.2(13), RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2002 by cisco Systems, Inc.
Compiled Tue 19-Nov-02 22:27 by pwade

advertisement version: 2


Device ID: Switch1
Entry address(es):
IP address: 172.25.1.4
Platform: WS-C2924, Capabilities: Trans-Bridge Switch
Interface: FastEthernet1/0, Port ID (outgoing port): FastEthernet0/12
Holdtime : 116 sec

Version :
Cisco Internetwork Operating System Software
IOS (tm) C2900XL Software (C2900XL-C3H2S-M), Version 12.0(5)WC3b, RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2002 by cisco Systems, Inc.
Compiled Fri 15-Feb-02 10:14 by antonino

advertisement version: 2
Duplex: full

Router1#

There is a lot of information in this output. It tells you the IP addresses of the adjacent interfaces on the neighbor devices. It also gives details about the Cisco IOS or CatOS version.

Both of these neighbor devices support CDP Version 2. In IOS Version 12.0(3)T, Cisco introduced this new version of CDP, which includes three new fields that are quite useful on LANs: VTP Domain Name, 802.1Q Native VLAN, and duplex. As you can see in the above output, the router and switch agree that they are operating at full duplex. Please refer to Chapter 16 for discussions of both 802.1Q and Ethernet Duplex configuration.

This new duplex option in particular is extremely useful because the router and switch can now automatically detect duplex mismatches. We deliberately created a duplex problem by changing the switch's setting to half duplex for the port facing this router. The router was able to detect the problem through CDP and issue the following log message:

Feb  6 11:36:11: %CDP-4-DUPLEX_MISMATCH: duplex mismatch discovered on
FastEthernet1/0 (not half duplex), with 003541987 (switch) FastEthernet0/12 (half duplex).

CDP Version 2 is enabled by default on all IOS versions 12.0(3)T and higher. You can globally disable Version 2 support on a router, allowing only Version 1, by issuing the following global configuration command:

Router1(config)#no cdp advertise-v2

However, it is not entirely clear what purpose this would serve. We know of no interoperability problems between CDP Version 1 and Version 2. And, while there are security problems, which we will discuss in Recipe 2.6, they are better addressed by disabling CDP altogether.

You can see global information about the router's CDP configuration with the show cdp command:

Router1#show cdp
Global CDP information:
Sending CDP packets every 60 seconds
Sending a holdtime value of 180 seconds
Sending CDPv2 advertisements is enabled
Router1#

Here you can see that this router sends out CDP advertisement packets every 60 seconds, which is the default. The holdtime parameter is the length of time the router will wait to hear the next CDP advertisement from one of its neighbors. If it doesn't receive this advertisement packet within this time period, the router will flush the corresponding entry from its CDP neighbor table.

You can adjust these parameters globally for the entire router as follows:

Router1(config)#cdp timer 30
Router1(config)#cdp holdtime 240

Both of these commands accept an argument in seconds. The advertisement timer can have any value between 5 and 254 seconds, while the hold timer must be between 10 and 255 seconds.

See Also