Cisco Discovery Protocol (CDP)
Published: 2023-08-06 18:49:56


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jk7rzocosds4f51jx4h1.png)
Cisco Discovery Protocol (CDP) is a Cisco proprietary protocol used to discover devices locally attached to the network. CDP is helpful in troubleshooting and mapping the entire network because the administrator can gather information about protocols and hardware of neighboring devices. For example, if it is lacking details in the documentation, running CDP commands will help to understand and create a logical topology.

It is essential to point out that as CDP is Cisco proprietary, it will only discover other Cisco devices. If we have different vendors' devices in our network we will resort to Link Layer Discovery Protocol (LLDP). LLDP has the same function as CDP. Both protocols run at layer 2 in the OSI model.

## How CDP works?
Cisco devices send periodically CDP messages out of each of their interfaces to devices connected using multicast frames and share information such as their hostname, device model, IOS version, types of interface, etc.

The devices that receive CDP messages don’t forward them to other devices. It is dumped. In addition, messages are sent once every 60 seconds by default.

## How to configure and verify CDP?
In Cisco devices, CDP is enabled by default. It is the administrator’s responsibility and choice to decide whether to disable it globally or in an interface, or to let it be enabled as default.

For security reasons, it might be a better option not to use CDP as this brings the risk of attackers having valuable information about the network in case they manage to break in. Once again, it is up to the administrator to balance what is best for their system.

So let’s see some useful commands!

**1- To check the CDP status run the command <show cdp>**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/npkdkanvri6sta7n5xx9.png)

**2- To enable CDP globally for all interfaces run `cdp run` in global configuration mode. On the other hand, to disable it for all interfaces, `no cdp run`.**

`Router# configure terminal
Router(config)# no cdp run
Router(config)# exit
Router# show cdp
CDP is not enabled
Router# configure terminal
Router(config)# cdp run`

**3- To enable or disable a single interface run `no cdp enable` and `cdp enable` respectively.**

`Switch(config)# interface gigabitethernet 0/0/1
Switch(config-if)# cdp enable
Switch(config)# interface gigabitethernet 0/0/2
Switch(config-if)# no cdp enable`

**4- In privilege mode, run `show cdp neighbors` or `sh cdp nei`, as a short version command, to show a list of neighbor devices.**

`R1>en
R1#show cdp neighbors
Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
                  S - Switch, H - Host, I - IGMP, r - Repeater, P - Phone
Device ID    Local Intrfce   Holdtme    Capability   Platform    Port ID
S1           Gig 0/0/0        160                    3650        Gig 1/0/1
In this network, there is a switch attached to a router. The router interface (local interface) is Gig 0/0/0 and Port ID (Gig 1/0/1) is the switch interface that is attached to the router.`

The command <show cdp neighbors> is also useful if we can telnet another device. By telnetting another device in the network and running this command, we are able to know what devices are connected to that specific device that we telneted.

**5- If we want to have the IP address of the neighboring device and have more details, we can run `show cdp neighbors detail` or just the short command, `sh cdp nei d`.**

`R1#show cdp neighbors detail
Device ID: S1
Entry address(es): 
  IP address : 192.168.1.61
Platform: cisco 3650, Capabilities: 
Interface: GigabitEthernet0/0/0, Port ID (outgoing port): GigabitEthernet1/0/1
Holdtime: 138
Version :
Cisco IOS Software [Denali], Catalyst L3 Switch Software (CAT3K_CAA-UNIVERSALK9-M), Version 16.3.2, RELEASE SOFTWARE (fc4)
Technical Support : http://www.cisco.com/techsupport
Copyright(c) 1986 - 2016 by Cisco Systems, Inc.
Compiled Tue 08 - Nov - 16 17:31 by pt_team
Cisco IOS-XE software, Copyright(c) 2005 - 2016 by cisco Systems, Inc.
All rights reserved.Certain components of Cisco IOS - XE software are
licensed under the GNU General Public License("GPL") Version 2.0.The
software code licensed under GPL Version 2.0 is free software that comes
with ABSOLUTELY NO WARRANTY.You can redistribute and / or modify such
GPL code under the terms of GPL Version 2.0.For more details, see the
documentation or "License Notice" file accompanying the IOS - XE software,
or the applicable URL provided on the flyer accompanying the IOS - XE
software.
advertisement version: 2
Duplex: full`

**6- To show interfaces that are CDP enabled run `show cdp interface`.**

`R1#show cdp interface
Vlan1 is administratively down, line protocol is down
  Sending CDP packets every 60 seconds
  Holdtime is 180 seconds
GigabitEthernet0/0/0 is up, line protocol is up
  Sending CDP packets every 60 seconds
  Holdtime is 180 seconds
GigabitEthernet0/0/1 is administratively down, line protocol is down
  Sending CDP packets every 60 seconds
  Holdtime is 180 seconds
Serial0/1/0 is up, line protocol is up
  Sending CDP packets every 60 seconds
  Holdtime is 180 seconds
Serial0/1/1 is administratively down, line protocol is down
  Sending CDP packets every 60 seconds
  Holdtime is 180 seconds`

Thank you for reading!