lldpcli / lldpctl
LLDP (Link Layer Discovery Protocol) lets every device tell its direct neighbour its name and port. With lldpd and lldpcli a Linux server answers the classic data-center question: which switch and which port is this cable plugged into?
61.1 What it is and where it runs
- LLDP: each device advertises its name, port and management IP to its direct neighbour (IEEE 802.1AB).
- lldpd: the daemon that sends and receives LLDP frames (apt install lldpd, systemctl enable --now lldpd).
- lldpcli: talks to the daemon to show, watch and configure.
- lldpctl: the legacy alias; it only prints the neighbour dump.
- Runs on Linux and macOS (brew install lldpd); not available on Windows.
61.2 How it works
- Every 30 seconds (default tx-interval) lldpd sends an LLDPDU out of each port with SysName, PortID, MgmtIP and capabilities.
- The frame goes to the special multicast MAC 01:80:c2:00:00:0e.
- A switch receives this MAC but never forwards it, so LLDP travels exactly one hop.
- The switch sends its own frame back (name core-sw1, port swp24, VLAN), so both sides learn each other.
- A neighbour entry expires after TTL = tx-hold x tx-interval (default 4 x 30 = 120 s).
- Step 1
1.lldpd on web01 sends an LLDPDU out of eth0 (dst 01:80:c2:00:00:0e)
- Step 2
2.The frame carries SysName web01, PortID and MgmtIP 192.168.81.10
- Step 3
3.core-sw1 receives it on swp24 and stores web01 as a neighbour
- Step 4
4.core-sw1 sends its own LLDPDU back: SysName core-sw1, PortDescr swp24
- Step 5
5.web01 runs lldpcli show neighbors: eth0 -> core-sw1 / swp24
Repeats every 30 s; the entry expires after TTL 120 s
- Step 1
1.web01 sends an LLDPDU towards core-sw1
- Step 2
2.core-sw1 receives it but never forwards it to the router
- Step 3
3.The router's lldpd sends its own LLDPDU to core-sw1
- Step 4
4.core-sw1 now knows two neighbours: web01 and router
- Step 5
5.web01 never learns about the router
Every device knows only its direct neighbour
61.3 show neighbors
- summary: just the neighbour name and port for each interface.
- ports eth0: full data for one interface, including MgmtIP, capabilities and TTL.
- Lab: web01 has two uplinks, eth0 to core-sw1 swp24 and eth1 to core-sw2 swp1.
lldpcli show neighbors summarylldpcli show neighbors ports eth0$ lldpcli show neighbors summaryInterface: eth0, via: LLDP SysName: core-sw1 PortID: mac 02:00:00:81:01:24 PortDescr: swp24Interface: eth1, via: LLDP SysName: core-sw2 PortDescr: swp1 $ lldpcli show neighbors ports eth0Interface: eth0, via: LLDP, RID: 2, Time: 0 day, 00:00:02 SysName: core-sw1 SysDescr: 48-port lab switch MgmtIP: 192.168.81.2 Capability: Bridge, off Capability: Router, on PortDescr: swp24 TTL: 12061.4 Program options
- lldpctl eth1: legacy full neighbour dump for one port.
- -f keyvalue: one field per line, easy to grep in scripts.
- -f json: parse with jq; -f json0 keeps a fixed structure, the safest for scripts.
- -u SOCK: talk to a specific daemon socket (here core-sw1's daemon in the lab).
- Keywords can be shortened: sh neigh p eth0 sum.
lldpctl eth1lldpcli -f keyvalue show neighbors \ | grep -E 'chassis.name|port.descr'lldpcli -f json show neighbors \ | jq -c '.lldp.interface[] | keys'lldpcli -u /run/n061/sw1.sock \ show chassis summary$ lldpctl eth1Interface: eth1, via: LLDP, RID: 1, Time: 0 day, 00:00:03 SysName: core-sw2 MgmtIP: 192.168.81.3 PortID: mac 02:00:00:81:02:01 PortDescr: swp1 TTL: 120 $ lldpcli -f keyvalue show neighbors | grep -E 'chassis.name|port.descr'lldp.eth0.chassis.name=core-sw1lldp.eth0.port.descr=swp24lldp.eth1.chassis.name=core-sw2lldp.eth1.port.descr=swp1 $ lldpcli -f json show neighbors | jq -c '.lldp.interface[] | keys'["eth0"]["eth1"] $ lldpcli -u /run/n061/sw1.sock show chassis summaryLocal chassis:Chassis: ChassisID: mac 02:00:00:81:01:24 SysName: core-sw1| Option | Meaning |
|---|---|
| lldpcli | Interactive shell with Tab completion |
| -d / -dd | Debug output (more with -dd) |
| -u SOCK | Daemon socket to use |
| -v / -vv | Version (build info with -vv) |
| -f plain | xml | json | json0 | keyvalue | Output format (plain is the default) |
| -c FILE | Read commands from a file |
| lldpctl [eth0 ...] | Legacy neighbour dump |
61.5 General commands
- help / help show neighbors: list commands and the keywords that can follow.
- update: send fresh LLDP frames on every port immediately.
- pause / resume: stop and restart lldpd operations (used in the interactive shell).
- exit: leave the interactive shell; here four commands were fed to the shell from a file.
lldpcli helplldpcli help show neighborslldpcli updatecat /tmp/shell.txtlldpcli < /tmp/shell.txt$ lldpcli help show Show running system information watch Monitor neighbor changes update Update information and send LLDPU on all ports configure Change system settingsunconfigure Unconfigure system settings pause Pause lldpd operations resume Resume lldpd operations exit Exit interpreter $ lldpcli help show neighbors details With more details summary With less details hidden Include hidden neighbors ports Restrict configuration to some ports protocol Restrict to specific protocol $ lldpcli update[exit 0] $ cat /tmp/shell.txtpauseshow statistics summaryresumeexit$ lldpcli < /tmp/shell.txt Transmitted: 6 Received: 5resumeexit61.6 show and watch commands
- show interfaces: what this host itself advertises (kernel tunnel interfaces like gretap0 and erspan0 also appear).
- show chassis: local hostname, chassis ID and management IP.
- show statistics summary: transmitted / received / discarded frame counters.
- watch limit 1: waits for one neighbour change and prints it; watch without a limit runs until Ctrl+C.
- hidden: also shows neighbours hidden by the smart filter; show configuration: global settings.
lldpcli show interfaces summarylldpcli show chassislldpcli show statistics summarylldpcli watch limit 1 summary$ lldpcli show interfaces summaryInterface: gretap0Interface: erspan0Interface: eth0 Administrative status: RX and TX PortID: mac 02:00:00:81:00:10Interface: eth1 $ lldpcli show chassis ChassisID: mac 02:00:00:81:00:10 SysName: web01 MgmtIP: 192.168.81.10 Capability: Router, on $ lldpcli show statistics summary Transmitted: 8 Received: 7 Discarded: 0 Unrecognized: 0 Inserted: 2 $ lldpcli watch limit 1 summaryLLDP neighbor updated:Interface: eth1, via: LLDP SysName: core-sw2-new PortDescr: swp161.7 configure system / unconfigure
- Changes are runtime only; persist them in /etc/lldpd.conf (or lldpd.d).
- interface pattern 'eth*': only matching interfaces run LLDP; ! excludes, !! forces in ('eth*,!eth1,!!eth2').
- hostname, description, capabilities enabled, ip management pattern: what the device advertises.
- Every configure has an unconfigure that restores the default (e.g. unconfigure system hostname).
- max-neighbors defaults to 32; bond-slave-src-mac-type sets the source MAC on bonded ports.
# web01lldpcli configure system interface pattern 'eth*'# core-sw1lldpcli configure system hostname core-sw1.lab.locallldpcli configure system description 'Rack3 access switch'lldpcli configure system capabilities enabled bridgelldpcli configure system ip management pattern 192.168.81.2# core-sw2lldpcli unconfigure system hostnameweb01$ lldpcli show interfaces summary | grep InterfaceInterface: eth0Interface: eth1 web01$ lldpcli show neighbors ports eth0 SysName: core-sw1.lab.local SysDescr: Rack3 access switch MgmtIP: 192.168.81.2 Capability: Bridge, on Capability: Router, off PortDescr: swp24 web01$ lldpcli show neighbors summary ports eth1Interface: eth1, via: LLDP SysName: core-sw2 PortDescr: swp161.8 configure lldp: protocol settings
- portidsubtype ifname: the PortID becomes swp24 instead of a MAC.
- ports swp24 lldp portdescription TEXT: a per-port description.
- tx-interval 10: a frame every 10 s; with tx-hold 4 the TTL becomes 40.
- ports eth1 lldp status rx-only: the port only listens, so Transmitted stayed at 7 even 35 s later.
- Status modes: rx-and-tx, rx-only, tx-only, disabled; other options: agent-type, vlan-tx, custom-tlv.
# core-sw1lldpcli configure lldp portidsubtype ifnamelldpcli configure ports swp24 lldp portdescription Server-rack3lldpcli configure lldp tx-interval 10# web01lldpcli configure ports eth1 lldp status rx-onlylldpcli show statistics ports eth1web01$ lldpcli show neighbors ports eth0 | grep -E 'Port|TTL' PortID: ifname swp24 PortDescr: Server-rack3 TTL: 40 core-sw1$ lldpcli show configuration | grep -iE 'transmit' Transmit delay: 10 Transmit hold: 4 web01$ lldpcli show interfaces ports eth1 | grep Admin Administrative status: RX onlyweb01$ lldpcli show statistics ports eth1 Transmitted: 7 Received: 5(35 seconds later) Transmitted: 7 Received: 761.9 med, dot3 and inventory: extra TLVs
- LLDP-MED needs lldpd -M <class>; -M 4 = Network Connectivity Device (a switch).
- med policy: tells IP phones the voice VLAN (500), priority and DSCP (46).
- med location: coordinates, civic address or ELIN (emergency number).
- dot3 power: the PoE TLV; role pse (gives power) or pd (takes power), power pairs, class 0-4.
- inventory: model, serial, revisions, manufacturer, asset; defaults from /sys/class/dmi, software revision from uname.
# core-sw1 (lldpd -M 4)lldpcli configure med policy application \ voice tagged vlan 500 priority voice dscp 46lldpcli configure med location elin 911lldpcli configure ports swp24 dot3 power \ pse supported enabled paircontrol \ powerpairs spare class class-3lldpcli configure inventory model SW-48Plldpcli configure inventory serial-number LAB0081# web01lldpcli show neighbors ports eth0 details$ lldpcli show neighbors ports eth0 details LLDP-MED: Device Type: Network Connectivity Device LLDP-MED Network Policy for: Voice, Defined: yes VLAN: 500 Priority: Voice PCP: 5 DSCP Value: 46 LLDP-MED Location Identification: Type: ELIN ECS ELIN: 911 MDI Power: Supported: yes, Enabled: yes, Pair control: yes Device type: PSE Power pairs: spare Class: class 3 Inventory: Software Revision: 9.3.1 Serial Number: LAB0081 Model: SW-48P| Group | What it advertises | Example |
|---|---|---|
| configure system | Identity of the device | hostname core-sw1.lab.local |
| configure lldp | Protocol timers and port ID | tx-interval 10, portidsubtype ifname |
| configure med | Voice VLAN, location, power (LLDP-MED) | policy application voice vlan 500 |
| configure dot3 | 802.3 PoE details | power pse ... class class-3 |
| configure inventory | Hardware/software inventory | model SW-48P |
61.10 Common mistakes
- Thinking LLDP gives a map of the whole network: it shows only the direct neighbour; a full map needs data from every switch (SNMP / automation).
- Empty show neighbors while the link is up: check lldpd is running, wait 30 s, then look at Received in show statistics.
- Received = 0 means LLDP is disabled on the switch port.
- Forgetting that configure changes are lost on restart unless written to lldpd.conf.
- Expecting MED/inventory TLVs without starting lldpd with -M.
61.11 Interview tips
- Which switch port is my NIC in? Install and enable lldpd, wait 30 s, run lldpcli show neighbors: SysName = switch, PortID/PortDescr = port.
- LLDP frames go to 01:80:c2:00:00:0e and are never forwarded: one hop only.
- TTL = tx-hold x tx-interval (default 4 x 30 = 120 s).
- Cisco networks also use CDP; lldpd can receive it with -c.
- For scripts use -f json0 or -f keyvalue.