How to Configure and Verify Layer 2 Discovery Protocols (Cisco Discovery Protocol and LLDP)

Configure and verify Layer 2 discovery protocols (Cisco Discovery Protocol and LLDP)

Have you ever walked into a server room, seen a wall of switches with dozens of cables, and wondered “what’s actually connected to what”? Layer 2 discovery protocols answer exactly that question — automatically, without you having to trace a single cable.

Cisco Discovery Protocol (CDP) and Link Layer Discovery Protocol (LLDP) are protocols that let directly connected network devices learn about each other — device type, hostname, IP address, platform, and which local port connects to which remote port — entirely automatically.

This article explains both protocols in depth, shows how to configure and verify them on Cisco devices, and explains why LLDP has become the preferred choice in modern multi-vendor networks.

Why Discovery Protocols Exist

Without a discovery protocol, documenting a network requires manually tracing cables or relying on outdated diagrams. In a data center with hundreds of switches, this becomes impractical. Discovery protocols solve this by having each device periodically advertise information about itself on every active interface, and listen for advertisements from directly connected neighbors.

This information is enormously useful for:

CDP: Cisco Discovery Protocol

CDP is a Cisco-proprietary Layer 2 protocol. It only works between Cisco devices (or devices from vendors who have licensed/implemented it). It operates directly at Layer 2, using a multicast destination MAC address (01:00:0c:cc:cc:cc), and it works regardless of Layer 3 configuration — even on interfaces with no IP address at all.

CDP Characteristics

CDP Configuration

CDP is on by default, but here’s how to control it explicitly.

Enable CDP globally (rarely needed, since it’s on by default):

Switch(config)# cdp run

Disable CDP globally (for security hardening on edge-facing devices):

Switch(config)# no cdp run

Disable CDP on a specific interface (recommended on interfaces facing untrusted networks, like ISP-facing WAN links):

Switch(config)# interface GigabitEthernet0/1
Switch(config-if)# no cdp enable

Re-enable CDP on a specific interface:

Switch(config-if)# cdp enable

Adjust timers (optional):

Switch(config)# cdp timer 30
Switch(config)# cdp holdtime 90

CDP Verification Commands

show cdp neighbors — quick summary view:

Switch# 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
SW2              Gig 0/1            156           S       WS-C3560  Gig 0/2
R1               Gig 0/2            178           R       C892FSP   Gig 0/0

show cdp neighbors detail — full detail, including IP address, software version, and duplex:

Switch# show cdp neighbors detail
-------------------------
Device ID: SW2
Entry address(es):
  IP address: 192.168.1.2
Platform: cisco WS-C3560-24PS,  Capabilities: Switch IGMP
Interface: GigabitEthernet0/1,  Port ID (outgoing port): GigabitEthernet0/2
Holdtime : 145 sec

Version :
Cisco IOS Software, C3560 Software...

advertisement version: 2
Duplex: full
Management address(es):

show cdp interface — confirms which interfaces have CDP enabled:

Switch# show cdp interface
GigabitEthernet0/1 is up, line protocol is up
  Encapsulation ARPA
  Sending CDP packets every 60 seconds
  Holdtime is 180 seconds

show cdp entry <device-name> — details for one specific neighbor by name.

LLDP: Link Layer Discovery Protocol

LLDP (IEEE 802.1AB) is the open, vendor-neutral standard equivalent to CDP. Because it’s an IEEE standard, LLDP works across Cisco, Juniper, HP, Arista, Linux servers, IP phones, and virtually any modern networking equipment — making it the correct choice for multi-vendor environments.

LLDP Characteristics

LLDP Configuration

Enable LLDP globally:

Switch(config)# lldp run

Disable LLDP globally:

Switch(config)# no lldp run

Enable/disable LLDP transmit and receive per interface:

Switch(config)# interface GigabitEthernet0/1
Switch(config-if)# lldp transmit
Switch(config-if)# lldp receive

To disable only transmission (still receive/listen) or vice versa:

Switch(config-if)# no lldp transmit
Switch(config-if)# no lldp receive

Adjust timers (optional):

Switch(config)# lldp timer 30
Switch(config)# lldp holdtime 120
Switch(config)# lldp reinit 2

LLDP Verification Commands

show lldp neighbors:

Switch# 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
SW2.example.com     Gi0/1          120        B               Gi0/2

show lldp neighbors detail:

Switch# show lldp neighbors detail
------------------------------------------------
Local Intf: Gi0/1
Chassis id: aabb.cc00.0200
Port id: Gi0/2
Port Description: GigabitEthernet0/2
System Name: SW2.example.com
System Description:
Cisco IOS Software...
Time remaining: 98 seconds
System Capabilities: B
Enabled Capabilities: B
Management Addresses:
    IP: 192.168.1.2

show lldp interface:

Switch# show lldp interface GigabitEthernet0/1
GigabitEthernet0/1:
    Tx: enabled
    Rx: enabled
    Tx state: IDLE
    Rx state: WAIT FOR FRAME

Visualizing Discovery Protocol Exchange

sequenceDiagram
    participant SW1
    participant SW2
    SW1->>SW2: CDP/LLDP advertisement (hostname, platform, IP, port ID)
    SW2->>SW1: CDP/LLDP advertisement (hostname, platform, IP, port ID)
    Note over SW1,SW2: Each device stores neighbor info in local table
    SW1->>SW1: show cdp neighbors / show lldp neighbors
    SW2->>SW2: show cdp neighbors / show lldp neighbors

CDP vs. LLDP: Comparison Table

FeatureCDPLLDP
VendorCisco proprietaryIEEE 802.1AB open standard
Default stateEnabled by defaultDisabled by default (on most Cisco platforms)
Multi-vendor supportNo (Cisco/licensed devices only)Yes
Default advertisement timer60 seconds30 seconds
Default holdtime180 seconds120 seconds
VoIP extensionsCisco proprietary (CDP-based phone discovery)LLDP-MED (standardized)
Works over Layer 2 only (no IP needed)YesYes
Recommended for multi-vendor networksNoYes
Security considerationCan leak topology info to attackers if left on untrusted portsSame consideration

A Practical Example: Discovering an Unknown Cable Connection

Imagine you’re troubleshooting and don’t know which physical port on SW1 connects to which port on the core switch. Instead of physically tracing the cable:

SW1# show cdp neighbors detail
-------------------------
Device ID: CORE-SW
Entry address(es):
  IP address: 10.1.1.1
Platform: cisco WS-C9300-48P,  Capabilities: Switch IGMP
Interface: GigabitEthernet0/24,  Port ID (outgoing port): TenGigabitEthernet1/1/1

In seconds, you know: SW1’s Gi0/24 connects directly to the core switch’s Te1/1/1 — no physical tracing required.

Python Example: Parsing Discovery Protocol Output for Automation

Network automation scripts frequently parse CDP/LLDP output to auto-generate topology diagrams. Here’s a simplified example:

import re

cdp_output = """
Device ID: SW2
Interface: GigabitEthernet0/1,  Port ID (outgoing port): GigabitEthernet0/2
"""

pattern = re.compile(
    r"Device ID:\s*(?P<device>\S+).*?"
    r"Interface:\s*(?P<local_intf>\S+),\s*Port ID \(outgoing port\):\s*(?P<remote_intf>\S+)",
    re.DOTALL
)

match = pattern.search(cdp_output)
if match:
    link = match.groupdict()
    print(f"Local port {link['local_intf']} connects to "
          f"{link['device']} port {link['remote_intf']}")

Output:

Local port GigabitEthernet0/1 connects to SW2 port GigabitEthernet0/2

Tools like Nornir, NAPALM, and network topology mapping platforms use exactly this kind of parsing — often at scale across hundreds of devices via SSH or NETCONF — to build automatic network maps.

Security Considerations

Discovery protocols reveal detailed information about your internal network: hostnames, IP addresses, platform/model, and IOS version. This is valuable for legitimate administrators, but equally valuable to an attacker who has gained access to a port.

Best practice: Disable CDP and LLDP on interfaces that face:

Switch(config)# interface GigabitEthernet0/24
Switch(config-if)# no cdp enable
Switch(config-if)# no lldp transmit
Switch(config-if)# no lldp receive

Exception: Leave LLDP (with LLDP-MED) enabled on access ports connecting Cisco IP Phones, since phones rely on it for auto-configuration of voice VLAN and power negotiation.

Best Practices

  1. Use LLDP in multi-vendor environments — it’s the only discovery protocol guaranteed to work across all manufacturers.
  2. Keep CDP enabled internally on all-Cisco environments for the richest neighbor detail (Cisco-specific fields).
  3. Disable both protocols on edge-facing/untrusted interfaces to reduce information leakage.
  4. Use show cdp/lldp neighbors detail (not the summary command) when doing serious troubleshooting — the detail view includes IP addresses and software versions critical for diagnosis.
  5. Standardize hostnames across your devices — discovery protocols are only as useful as the naming convention behind them.
  6. Automate topology documentation using discovery protocol output rather than maintaining static diagrams manually.

Troubleshooting

Symptom: A Neighbor Isn’t Showing Up

Checklist:

  1. Confirm the protocol is enabled globally: show cdp / show lldp (no arguments) shows global status.
  2. Confirm the protocol is enabled on the specific interface: show cdp interface / show lldp interface.
  3. Confirm the physical link is actually up: show interfaces status.
  4. Confirm there isn’t a firewall, media converter, or unmanaged switch in between silently blocking Layer 2 multicast frames.
  5. Wait a full advertisement cycle — a brand-new link may take up to 60 seconds (CDP) or 30 seconds (LLDP) to populate.

Symptom: Stale/Outdated Neighbor Entries

Cause: The neighbor was reconfigured/removed but its old entry hasn’t aged out yet.

Fix: Wait for the holdtime to expire (180s CDP / 120s LLDP), or manually clear the table:

Switch# clear cdp table
Switch# clear lldp table

Symptom: IP Phone Not Getting Voice VLAN

Cause: LLDP-MED not enabled or not transmitting correctly on the access port.

Fix: Verify lldp transmit and lldp receive are both enabled, and confirm the voice VLAN is properly configured under the switchport.

Summary

CDP and LLDP are indispensable Layer 2 tools that let devices automatically learn about their directly connected neighbors — no manual cable tracing required. CDP is Cisco-proprietary and on by default; LLDP is the IEEE-standard, vendor-neutral equivalent and must usually be enabled explicitly. In modern, multi-vendor networks, LLDP is the preferred protocol, but many all-Cisco shops still rely heavily on CDP for its richer detail. Either way, mastering show cdp/lldp neighbors detail will make troubleshooting and documentation dramatically faster.

Further Reading

Exit mobile version