Course contents

Chapter 1: Cisco IOSLesson 8 of 10

Discovering neighbours with CDP and LLDP

Using CDP and LLDP to map a network, and when to turn them off.

Intermediate · 9 min read

Technical definition

CDP (Cisco Discovery Protocol) and LLDP (Link Layer Discovery Protocol) are Layer 2 neighbour discovery protocols: each device periodically advertises its identity, platform, port and addresses out of its interfaces, and directly connected devices store what they receive in a neighbour table. CDP is Cisco proprietary; LLDP is the vendor-neutral IEEE 802.1AB standard.

Find the device at the other end of a cable

Run show cdp neighbors or show lldp neighborsto identify a connected device and the port at each end of its link. Use CDP between supported Cisco devices and LLDP for a mixed-vendor network. Check support and defaults for your platform; a device may support either protocol, both, or neither.

Both share information such as:

  • the neighbour's name (the Device ID, usually its hostname),
  • the neighbour's own interface the cable is plugged into (the Port ID),
  • its capabilities (router, switch, phone, access point),
  • system information and management addresses, when advertised.
Diagram
Who can see whom with CDP and LLDP
Who can see whom with CDP and LLDP
Gi0/1Gi1/0/24Gi0/2Gi1/0/24Gi0/0Gi1/0/20Gi1/0/1R1Cisco ISRSW1C9200LSW2C9200LAP-FLOOR1third-party APPC1IP 192.168.10.10ISP

Device key: R1 (router) · SW1, SW2 (switch) · AP-FLOOR1 (access point) · PC1 (computer) · ISP (network / service)

Lines show the example’s network connections. Thick links: uplinks/WAN, as labelled. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • R1: Cisco ISR
  • SW1: C9200L
  • SW2: C9200L
  • AP-FLOOR1: third-party AP
  • PC1: IP 192.168.10.10
  1. 1. SW1 and SW2 advertise to R1. Each switch advertises on its active CDP-enabled ports; R1 records both neighbours, with the port at each end.
  2. 2. R1 advertises back. Discovery runs in both directions, so each switch also lists R1.
  3. 3. The third-party AP speaks only LLDP. SW1 sees AP-FLOOR1 only if LLDP is enabled on SW1. CDP alone would miss it.
  4. 4. CDP toward the ISP is a leak. R1 would advertise its model and IOS version to a network you don't control. Turn CDP off on Gi0/0.
  5. 5. Only one hop. SW1 does not pass the AP's or anyone else's messages on. R1 never learns about AP-FLOOR1 or PC1.

Why discovery stops at one hop

Diagram
R1 sees its switch, not the AP behind that switch
R1 sees its switch, not the AP behind that switch
R1 sees its switch, not the AP behind that switchR1 Gi0/1 connects to SW1 Gi1/0/24. A CDP-capable AP connects to SW1 Gi1/0/10. With CDP enabled on these links, R1 normally learns SW1; SW1 learns R1 and the AP. SW1 terminates their advertisements rather than relaying them as remote neighbours.R1SW1AP-FLOOR1Gi0/1Gi1/0/24Gi1/0/10R1 neighbour tableSW1 on local Gi0/1AP-FLOOR1 is not R1’s direct peer.SW1 neighbour tableR1 on local Gi1/0/24AP-FLOOR1 on local Gi1/0/10
A normal CDP-enabled switched lab. Discovery describes directly attached peers; hubs, tunnelling and devices that flood CDP can produce different observations. LLDP has its own reserved multicast forwarding rules.

CDP and LLDP run at Layer 2. Each message is an Ethernet frame sent to a reserved multicast MAC address (CDP uses 01:00:0C:CC:CC:CC, LLDP uses 01:80:C2:00:00:0E). Because no IP is involved, discovery works even before addresses are configured or when IP is misconfigured. That is exactly when you need it most.

A device that understands the protocol keeps the frame and does not forward it. That is deliberate: the table should describe the cable you are standing at, not a device three switches away. A Cisco switch therefore normally lists only the devices it is directly cabled to. A hub or a switch that floods CDP frames can make several neighbours appear on one port. Do not assume LLDP passes through the same way: its reserved destination is normally filtered by Ethernet bridges.

Advertisements, holdtime and expiry

Each message carries a holdtime: how long the receiver should keep the entry if it hears nothing more. The sender repeats its message on a timer well inside that holdtime, so a healthy neighbour never expires.

Diagram
A CDP neighbour entry expires from its last received advertisement
A CDP neighbour entry expires from its last received advertisement
A CDP neighbour entry expires from its last received advertisementWith the illustrated default timers, CDP advertisements arrive at 0 and 60 seconds. Each refresh grants a new 180-second holdtime. If no later advertisement arrives, the entry from the 60-second refresh expires at 240 seconds. A local link-down event can remove the entry sooner.R1SW1CDP advertisement → neighbour cache on SW10 sReceiveExpires at 180 s60 sReceive + refreshNew expiry: 240 s120 sNo new messageEntry still cached240 sHoldtime expiresRemove the entryA cached neighbour is not proof that the link is working now.
Default CDP example: transmit interval 60 s, holdtime 180 s. Verify actual timers with show cdp. This expiry model does not assume the local link goes down.
Diagram
Advertisements, holdtime and expiry
Advertisements, holdtime and expiry
SettingCDPLLDP
StandardCisco proprietaryIEEE 802.1AB (open)
Typical IOS / IOS XE global default*EnabledDisabled
Advertisement timer60 s30 s
Holdtime180 s120 s
Turn on/off globallycdp run / no cdp runlldp run / no lldp run
Per interfacecdp enable / no cdp enablelldp transmit and lldp receive (separately)
Read each row across: the left box names the item, the others describe it.

*Defaults and supported interfaces vary by platform and release. Verify with show cdp and show lldp.

Turning CDP and LLDP on and off

Based on Cisco IOS / IOS XE documentation, not run on a lab device.

CDP

cdp run interface GigabitEthernet0/0 no cdp enable

cdp run is the default, shown for completeness. Turn CDP off on the interface that faces the ISP. no cdp run would turn it off on every interface at once.

cdp timer 30 cdp holdtime 90

Optional: change how often CDP is sent and how long neighbours keep the entry. Keep the holdtime longer than the timer (three times is the usual ratio).

LLDP

lldp run interface GigabitEthernet1/0/20 lldp transmit lldp receive

On SW1: enable LLDP globally. Explicitly enable transmit and receive on the AP-facing port. Check show lldp interface to confirm its state.

interface range GigabitEthernet1/0/2 - 19 no lldp transmit no cdp enable

On user-facing access ports where no network device or phone connects, stop advertising. You can keep receiving with lldp receive if you want to see what users plug in.

lldp timer 30 lldp holdtime 120 lldp reinit 2

The defaults: advertise every 30 s, hold for 120 s, and wait 2 s before restarting LLDP on an interface after it is re-enabled.

A full example: R1

! Keep CDP for the internal links, drop it toward the ISP cdp run lldp run interface GigabitEthernet0/0 description WAN to ISP no cdp enable no lldp transmit no lldp receive

Discovery on the LAN side, silence on the internet side.

Reading the neighbour tables

Read the cable from R1 to SW1On R1, Local Intrfce Gi0/1 is the local port. Device ID SW1 names the neighbour. Port ID Gi1/0/24 is SW1's port at the other end of the cable.R1 · you are hereSW1 · neighbourR1SW1Gi0/1Gi1/0/24Local IntrfcePort IDOne Ethernet cable
Read from the device where you ran the command: local is your port; Port ID belongs to the neighbour.
Example output · based on Cisco documentation; exact format varies by platform and software version
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
SW1              Gig 0/1           152             S I    C9200L-24 Gig 1/0/24
SW2              Gig 0/2           147             S I    C9200L-24 Gig 1/0/24

Total cdp entries displayed : 2
Local Intrfce is R1's port; Port ID is the neighbour's port. Read each line as "my Gi0/1 connects to SW1's Gi1/0/24". Holdtme counts down and jumps back up with each new message. There is no IP address here; you need the detail view for that.
Example output · based on Cisco documentation; exact format varies by platform and software version
R1#show cdp neighbors detail
-------------------------
Device ID: SW1
Entry address(es):
  IP address: 192.168.10.2
Platform: cisco C9200L-24T-4G,  Capabilities: Switch IGMP
Interface: GigabitEthernet0/1,  Port ID (outgoing port): GigabitEthernet1/0/24
Holdtime : 138 sec

Version :
Cisco IOS Software [Cupertino], Catalyst L3 Switch Software (CAT9K_LITE_IOSXE), Version 17.9.4, RELEASE SOFTWARE (fc5)

advertisement version: 2
Native VLAN: 1
Duplex: full
Management address(es):
  IP address: 192.168.10.2
-------------------------
...
The detail view adds the neighbour's IP address (a candidate address for management, if reachable) and its advertised software version. That version line is precisely what an attacker would want to see. show cdp entry SW1 shows the same for one neighbour.
Example output · based on Cisco documentation; exact format varies by platform and software version
R1#show cdp
Global CDP information:
        Sending CDP packets every 60 seconds
        Sending a holdtime value of 180 seconds
        Sending CDPv2 advertisements is  enabled
The global timers. show cdp interface lists which interfaces are running CDP; Gi0/0 should be missing from that list after no cdp enable.
Example output · based on Cisco documentation; exact format varies by platform and software version
SW1#show lldp neighbors
Capability codes:
    (R) Router, (B) Bridge, (T) Telephone, (C) DOCSIS Cable Device
    (W) WLAN Access Point, (P) Repeater, (S) Station, (O) Other

Device ID           Local Intf     Hold-time  Capability      Port ID
R1                  Gi1/0/24       120        R               Gi0/1
AP-FLOOR1           Gi1/0/20       120        W               eth0

Total entries displayed: 2
The same idea in LLDP's format. A switch shows up as B (bridge) in LLDP. The third-party access point appears here even though it doesn't speak CDP. Port IDs are whatever the neighbour reports, so a non-Cisco device may show a name like eth0 or a MAC address.
Example output · based on Cisco documentation; exact format varies by platform and software version
SW1#show lldp
Global LLDP Information:
    Status: ACTIVE
    LLDP advertisements are sent every 30 seconds
    LLDP hold time advertised is 120 seconds
    LLDP interface reinitialisation delay is 2 seconds
If LLDP is off you see % LLDP is not enabled instead. Use show lldp neighbors detail for addresses and versions, and show lldp interface for per-port settings.

Missing, stale and surprising neighbours

  • A neighbour you expect is missing. Check the link is up/up with show ip interface brief; discovery needs a working Layer 2 link. Then check the protocol is running on both ends (show cdp interface, show lldp interface). Wait up to a full timer interval after a change.
  • A non-Cisco device doesn't appear. Most non-Cisco devices don't speak CDP. Enable LLDP with lldp run.
  • An old neighbour is still listed after recabling. An entry can remain until its holdtime runs out if it was not removed on link-down. To remove cached entries immediately, use clear cdp table or clear lldp table.
  • IP phones lose their voice VLAN. Phones can learn the voice VLAN through CDP or LLDP-MED, depending on the device and configuration. Before disabling discovery, check which protocol the phone uses for VLAN and power negotiation.
  • The table shows a device you didn't expect, several hops away. A device between you that doesn't process CDP may flood its multicast frames. A hub can also repeat them, making two Cisco devices appear directly connected. Trace the physical path before relying on that assumption.

Check the result

  1. Confirm the expected neighbour and both port IDs in the table.
  2. Use the detail view to inspect advertised management addresses. Test IP reachability separately before trying SSH.
  3. Confirm discovery is disabled on the untrusted interface and still running on the intended internal ports.
  4. Save the configuration with copy running-config startup-config.

For link and IP checks, see Cisco show commands.

Test yourself on CDP and LLDP

Predict · scenario 1

On R1, show cdp neighbors shows 'SW2 Gig 0/2 147 S I C9200L-24 Gig 1/0/24'. Which port on SW2 is the cable plugged into?

Predict · scenario 2

SW1 connects to an AP that advertises LLDP but not CDP. The link is up, but LLDP is disabled on SW1. What should you enable?

Predict · scenario 3

R1 is connected to SW1, and SW1 to SW2. Both switches are Cisco with CDP on. Does show cdp neighbors on R1 list SW2?

Predict · scenario 4

You want to stop CDP only on R1's internet-facing Gi0/0 and keep it everywhere else. Which command do you use?

Predict · scenario 5

What are the default LLDP advertisement timer and holdtime?

References