Intermediate · Switching and VLANs · topic 24 of 57 · 25 min
CDP and LLDP: discovering neighbours
Explanation
What problem do they solve?
You join a company as a network engineer. The diagram on the wiki is three years old. Which switch is connected to which port of the core? What model is it? What is its management IP address? Walking to every rack and tracing cables takes days. Discovery protocols answer these questions in seconds from the command line.
A discovery protocol makes each device send a small message out of every port at a regular interval, saying "I am SW2, a Cisco 2960, this is my port Gi0/1, my IP address is 10.0.0.2". The devices directly connected (the neighbours) store this information. Messages are not forwarded further, so you only learn about devices one hop away.
CDP: Cisco Discovery Protocol
- Cisco proprietary: mainly Cisco devices (and some others, like IP phones) understand it.
- Enabled by default on Cisco IOS routers and switches.
- Sent every 60 seconds by default (the CDP timer).
- Holdtime 180 seconds: if no message arrives for 180 seconds, the neighbour is removed from the table.
- Works at layer 2, so it works even before IP addresses are configured.
SW1# 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
R1 Gig 0/1 163 R B S I ISR4331 Gig 0/0/0
SW2 Gig 0/2 141 S I WS-C2960 Gig 0/1Read each line as: "On my port (Local Intrfce) I can see device (Device ID), which is a (Platform), connected through its port (Port ID)." Holdtme counts down from 180 and is reset each time a message arrives.
show cdp neighbors detail adds the neighbour's IP address, full software version, native VLAN and duplex. That is how you find the management address of a switch you cannot reach otherwise, and spot native VLAN or duplex mismatches.
SW1(config)# no cdp run
SW1(config)# cdp run
SW1(config)# interface gigabitEthernet 0/5
SW1(config-if)# no cdp enable
SW1(config-if)# exit
SW1(config)# cdp timer 60
SW1(config)# cdp holdtime 180LLDP: the open standard
LLDP (Link Layer Discovery Protocol) is defined in IEEE 802.1AB. It does the same job as CDP but works across vendors: Cisco, Juniper, Aruba, Linux servers and many IP phones. In a mixed network, LLDP is what lets your Cisco switch see the HPE server or the Juniper firewall next to it.
- Sent every 30 seconds by default; holdtime 120 seconds.
- Off by default on many Cisco IOS devices. Turn it on globally with lldp run.
- Per interface you can control sending and receiving separately: lldp transmit and lldp receive.
- LLDP-MED, an extension, tells IP phones which voice VLAN to use, like CDP does for Cisco phones.
SW1(config)# lldp run
SW1(config)# interface gigabitEthernet 0/5
SW1(config-if)# no lldp transmit
SW1(config-if)# no lldp receive
SW1(config-if)# end
SW1# show lldp neighbors
SW1# show lldp neighbors detail| CDP | LLDP | |
|---|---|---|
| Standard | Cisco proprietary | IEEE 802.1AB (open) |
| Default on Cisco IOS | On | Often off (lldp run) |
| Timer / holdtime | 60 s / 180 s | 30 s / 120 s |
| Turn off on one port | no cdp enable | no lldp transmit, no lldp receive |
Security: why you turn them off at the edge
CDP and LLDP messages are sent in clear text to anyone connected. A visitor who plugs a laptop into a meeting-room port can capture one message and learn the switch name, exact model, software version and management IP address. With the version, they can look up known vulnerabilities. So the usual rule is: keep CDP or LLDP on links between your own network devices, and turn them off on ports facing users, the internet or other companies.
Using them to draw a network diagram
- Start at the core switch. Run show cdp neighbors (or show lldp neighbors).
- For each neighbour, draw a box and a line labelled with both port names, for example "CORE Gi1/0/1 to SW2 Gi0/1".
- Use show cdp neighbors detail to note each neighbour's management IP address.
- Log in to each neighbour in turn and repeat, until you find no new devices.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
CDP and LLDP: discovering neighbours · 1/7
In this lesson you will learn how a device can tell you what is connected to each of its ports.
Prefer a video by a teacher? Find free videos on “cdp lldp show cdp neighbors explained ccna” on YouTube ↗
In real life: A new engineer at a Kolkata bank branch network
A network engineer joins a cooperative bank with 40 branches. The only diagram is a scanned drawing from 2019. In her first week she logs in to the data-centre core switch, runs show cdp neighbors detail, notes each neighbour's IP address, and hops from switch to switch. In two days she has a correct diagram showing every uplink and port number, and she finds one branch switch connected through a forgotten 100 Mbps port. She also turns off CDP on all user-facing ports as the bank's auditor recommended.
Practice (0/3 done)
show cdp neighbors on SW1 shows: Device ID SW3, Local Intrfce Gig 0/4, Port ID Gig 0/1. Which statement is correct?
Write parse_cdp(text) for the neighbour table of show cdp neighbors. Each neighbour line looks like "SW2 Gig 0/2 141 S I WS-C2960 Gig 0/1": device, local interface (2 words), holdtime, capability codes (1 or more words), platform (1 word), port ID (2 words). Skip blank lines and the header line that starts with "Device ID". Return a list of dicts with keys "device", "local", "holdtime" (an int), "capability" (codes joined with one space), "platform" and "port".
Packet Tracer lab: build three switches in a line (SW1 Gi0/1 to SW2 Gi0/1, SW2 Gi0/2 to SW3 Gi0/1) and a PC on SW3 Fa0/1. Using only show cdp neighbors on each switch, draw the diagram with both port names on every link. Then turn off CDP on SW3 Fa0/1 (the user port) and enable LLDP on all switches.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Switch management and interface troubleshootingSwitching and VLANs · same module
- Trunks and 802.1Q taggingSwitching and VLANs · same module
- DHCP: automatic addressesIP services: DHCP, DNS, NAT and more
- Troubleshooting tools and common faultsTroubleshooting and the CCNA exam
- Ports and protocolsCyber Security: from zero to SOC analyst · Networking for security
- nmap scan typesEthical Hacking and Penetration Testing (legal labs) · Scanning with nmap
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
What are the default CDP timer and holdtime?
Answer: 60 s and 180 s
CDP sends every 60 seconds and keeps a neighbour for 180 seconds without a new message.
Which standard defines LLDP?
Answer: IEEE 802.1AB
LLDP is IEEE 802.1AB, a vendor-neutral standard.
Which command turns CDP off on just one interface?
Answer: no cdp enable
no cdp enable works in interface mode. no cdp run turns CDP off for the whole device.
Why disable CDP on ports that face users?
Answer: It reveals the device model, software version and IP address to anyone connected
CDP is clear text; the details help an attacker look for known weaknesses.
Your Cisco switch connects to a Linux server and a Juniper firewall. Which protocol shows them as neighbours?
Answer: LLDP
LLDP is the open standard that non-Cisco devices support.
An IP phone and a PC share one switch port. Which command puts the phone traffic in VLAN 50?Related
Answer: switchport voice vlan 50
switchport voice vlan 50 tells the phone to tag voice frames with VLAN 50; the PC stays in the access VLAN.
Which UDP port does a DHCP server listen on?Related
Answer: 67
The server uses UDP 67 and the client UDP 68. 53 is DNS and 69 is TFTP.
Two OSPF routers on the same link never become neighbours. Which mismatch can cause this?Related
Answer: Different hello and dead timers
Neighbours must agree on area, hello and dead timers, subnet and authentication. Hostnames and banners do not matter.
Which port does HTTPS use by default?Related
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 1 more topic in “Switching and VLANs” before its exam: Switch management and interface troubleshooting.
- Module 5 exam: Switching and VLANs · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
- Then the next module, Spanning Tree and EtherChannel. 57 topics left in the course before the final exam.