Skip to content

Intermediate · Switching and VLANs · topic 24 of 57 · 25 min

CDP and LLDP: discovering neighbours

Explanation

CDP (Cisco, on by default) and LLDP (an open IEEE standard) let a device announce its name, model, port and address to the devices directly connected to it. show cdp neighbors and show lldp neighbors tell you what is plugged into each port, which is how engineers draw or check a network diagram. Because they reveal details to anyone connected, turn them off on ports that face users or outside networks.

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.

Think of it like this: It is like a new housing society where every family puts a nameplate on its door. Standing in the corridor, you can read the names of your direct neighbours, but not of people on other floors. To map the whole building, you walk floor by floor and read the nameplates next to each door.

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.
output
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/1
Cisco IOS (trimmed): Local Intrfce is your port; Port ID is the neighbour's port. SW1 Gi0/2 connects to SW2 Gi0/1.

Read 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.

output
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 180
Cisco IOS: no cdp run turns CDP off for the whole device; no cdp enable turns it off on one interface.

LLDP: 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.
output
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
Cisco IOS: enable LLDP globally, disable it on one port, then look at the neighbours.
CDPLLDP
StandardCisco proprietaryIEEE 802.1AB (open)
Default on Cisco IOSOnOften off (lldp run)
Timer / holdtime60 s / 180 s30 s / 120 s
Turn off on one portno cdp enableno 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.

Careful: Careful on phone ports: IP phones use CDP or LLDP-MED to learn their voice VLAN. If you disable discovery on a phone port, the phone may land in the data VLAN. Test with one phone before changing a whole floor.

Using them to draw a network diagram

  1. Start at the core switch. Run show cdp neighbors (or show lldp neighbors).
  2. For each neighbour, draw a box and a line labelled with both port names, for example "CORE Gi1/0/1 to SW2 Gi0/1".
  3. Use show cdp neighbors detail to note each neighbour's management IP address.
  4. Log in to each neighbour in turn and repeat, until you find no new devices.
Tip: Common mistake: mixing up Local Intrfce and Port ID. Local is always your side of the cable. Write both on the diagram so that the next person can trace the cable from either end.

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

CDP and LLDP

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)

Task 1 · Question

show cdp neighbors on SW1 shows: Device ID SW3, Local Intrfce Gig 0/4, Port ID Gig 0/1. Which statement is correct?

Task 2 · Code · Python

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".

Task 3 · Practice

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

Question 1

1.What are the default CDP timer and holdtime?

Question 2

2.Which standard defines LLDP?

Question 3

3.Which command turns CDP off on just one interface?

Question 4

4.Why disable CDP on ports that face users?

Question 5

5.Your Cisco switch connects to a Linux server and a Juniper firewall. Which protocol shows them as neighbours?

Read more (free)

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.

From VLANs: what they are and why we use them

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.

From DHCP: automatic addresses

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.

From Troubleshooting tools and common faults

Which port does HTTPS use by default?Related

Answer: 443

HTTPS uses TCP 443 (and UDP 443 for HTTP/3).

From Ports and protocols

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. 1 more topic in “Switching and VLANs” before its exam: Switch management and interface troubleshooting.
  2. Module 5 exam: Switching and VLANs · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Spanning Tree and EtherChannel. 57 topics left in the course before the final exam.

← Previous: Inter-VLAN routing