How-Tos

How-To: Find Which Switch Port Your Linux Box Is Plugged Into With LLDP

Leave a comment

Tracing a cable through a messy rack is nobody’s idea of fun. If your switch speaks LLDP (most managed switches do, including Cisco), your Linux box can just tell you which switch and port it’s on.

1. Install and start lldpd

# Arch / Omarchy
sudo pacman -S lldpd
# Debian / Ubuntu
sudo apt install lldpd

sudo systemctl enable --now lldpd

2. Ask who your neighbors are

sudo lldpcli show neighbors

Give it about 30 seconds to hear an announcement. You’ll see the switch’s name, its management address if it advertises one, and the port you’re on, like Gi1/0/12. Add details for more, including VLAN info when the switch sends it.

3. Turn LLDP on for Cisco IOS if you see nothing

conf t
 lldp run
end
show lldp neighbors detail

Some Cisco gear only runs CDP by default. lldpd can listen for CDP too if you start it with -c (on Debian, put DAEMON_ARGS="-c" in /etc/default/lldpd and restart).

4. Prove frames are arriving

sudo tcpdump -i eth0 -nn -v -c 1 ether proto 0x88cc

Swap in your interface name. If that sits there forever, LLDP isn’t reaching the port.

A security note

LLDP hands out device names, models and sometimes addresses to anyone plugged in. Leave it on for infrastructure links, and turn transmit off on guest or untrusted edge ports (no lldp transmit on the interface in IOS). The lldpd usage page and lldpcli man page cover the rest.

God Bless, and May the Source Be with You!

References & Further Reading

Subscribe (RSS) Follow How-Tos via RSS

Leave a note

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.