SkillPilotAI

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).
LLDP exchange between web01 and core-sw1
  1. 1.lldpd on web01 sends an LLDPDU out of eth0 (dst 01:80:c2:00:00:0e)

  2. 2.The frame carries SysName web01, PortID and MgmtIP 192.168.81.10

  3. 3.core-sw1 receives it on swp24 and stores web01 as a neighbour

  4. 4.core-sw1 sends its own LLDPDU back: SysName core-sw1, PortDescr swp24

  5. 5.web01 runs lldpcli show neighbors: eth0 -> core-sw1 / swp24

Repeats every 30 s; the entry expires after TTL 120 s

One hop only
  1. 1.web01 sends an LLDPDU towards core-sw1

  2. 2.core-sw1 receives it but never forwards it to the router

  3. 3.The router's lldpd sends its own LLDPDU to core-sw1

  4. 4.core-sw1 now knows two neighbours: web01 and router

  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.
Terminal
lldpcli show neighbors summarylldpcli show neighbors ports eth0
Output
$ 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:          120

61.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.
Terminal
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
Output
$ 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
OptionMeaning
lldpcliInteractive shell with Tab completion
-d / -ddDebug output (more with -dd)
-u SOCKDaemon socket to use
-v / -vvVersion (build info with -vv)
-f plain | xml | json | json0 | keyvalueOutput format (plain is the default)
-c FILERead 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.
Terminal
lldpcli helplldpcli help show neighborslldpcli updatecat /tmp/shell.txtlldpcli < /tmp/shell.txt
Output
$ 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:     5resumeexit

61.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.
Terminal
lldpcli show interfaces summarylldpcli show chassislldpcli show statistics summarylldpcli watch limit 1 summary
Output
$ 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:    swp1

61.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.
Terminal
# 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 hostname
Output
web01$ 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:    swp1

61.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.
Terminal
# 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 eth1
Output
web01$ 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:     7

61.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.
Terminal
# 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
Output
$ 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
GroupWhat it advertisesExample
configure systemIdentity of the devicehostname core-sw1.lab.local
configure lldpProtocol timers and port IDtx-interval 10, portidsubtype ifname
configure medVoice VLAN, location, power (LLDP-MED)policy application voice vlan 500
configure dot3802.3 PoE detailspower pse ... class class-3
configure inventoryHardware/software inventorymodel 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.