如何查询linux服务器网卡所接交换机端口的LLDP信息

1、查询是否有按照lldpad的软件包,如果没有需要yum install lldpad

[root@backupsvr ~]#  rpm -qi lldpad
Name        : lldpad
Version     : 1.0.1
Release     : 5.git036e314.el7
Architecture: x86_64
Install Date: Thu 13 Jul 2023 04:53:04 PM CST
Group       : System Environment/Daemons
Size        : 714887
License     : GPLv2
Signature   : RSA/SHA256, Fri 24 May 2019 10:07:40 PM CST, Key ID 199e2f91fd431d51
Source RPM  : lldpad-1.0.1-5.git036e314.el7.src.rpm
Build Date  : Wed 27 Feb 2019 05:43:04 AM CST
Build Host  : x86-040.build.eng.bos.redhat.com
Relocations : (not relocatable)
Packager    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
Vendor      : Red Hat, Inc.
URL         : http://open-lldp.org/
Summary     : Intel LLDP Agent
Description :
This package contains the Linux user space daemon and configuration tool for
Intel LLDP Agent with Enhanced Ethernet support for the Data Center.

[root@backupsvr ~]# lldp
lldpad    lldptool  
[root@backupsvr ~]# lldptool

2、启动lldpad服务。
[root@backupsvr ~]# service lldpad status   
Redirecting to /bin/systemctl status lldpad.service
鈼lldpad.service - Link Layer Discovery Protocol Agent Daemon.
   Loaded: loaded (/usr/lib/systemd/system/lldpad.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
[root@backupsvr ~]# service lldpad start
Redirecting to /bin/systemctl start lldpad.service
[root@backupsvr ~]# service lldpad status
Redirecting to /bin/systemctl status lldpad.service
鈼[0m lldpad.service - Link Layer Discovery Protocol Agent Daemon.
   Loaded: loaded (/usr/lib/systemd/system/lldpad.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2023-11-02 12:27:29 CST; 5s ago
 Main PID: 33422 (lldpad)
   CGroup: /system.slice/lldpad.service
           鈹斺攢33422 /usr/sbin/lldpad -t

Nov 02 12:27:29 backupsvr systemd[1]: Started Link Layer Discovery Protocol Agent Daemon..


[root@backupsvr ~]# lldptool -l -i em1 adminStatus
adminStatus=disabled
[root@backupsvr ~]# 

4种模式说明:

TxRx:既发送也接收LLDP报文。

Tx:只发送不接收LLDP报文。

Rx:只接收不发送LLDP报文。

Disable:既不发送也不接收LLDP报文

3、开启网卡的lldp管理协议。
[root@backupsvr ~]# lldptool set-lldp -i em1 adminStatus=rxtx
adminStatus = rxtx

4、查询所接交换机端口信息。
[root@backupsvr ~]#  lldptool -t -n -i em1
Chassis ID TLV
        MAC: a2:18:3f:90:18:00
Port ID TLV
        Ifname: GE11/0/45             #(对端交换机的端口信息
Time to Live TLV
        120
Port Description TLV
        To-BeiFen0232                 #(端口描述
System Name TLV
        Switch_A                            #(交换机名称
System Description TLV
        Huawei Versatile Routing Platform Software
VRP (R) software, Version 8.120 (CE12800 V200R001C00SPC700)
Copyright (C) 2012-2016 Huawei Technologies Co., Ltd.
HUAWEI CE12812

System Capabilities TLV
        System capabilities:  Bridge, Router
        Enabled capabilities: Bridge, Router
Management Address TLV
        IPv4: 10.235.255.12
        Ifindex: 272
        OID: 0.6.14.45.6.1.4.1.-112.91.5.25.41.1.2.1.1.1
Port VLAN ID TLV
        PVID: 2300
Port and Protocol VLAN ID TLV
        PVID: 0, not supported, not enabled
VLAN Name TLV
        VID 2300: Name VLAN2300
MAC/PHY Configuration Status TLV
        Auto-negotiation supported and enabled
        PMD auto-negotiation capabilities: 0x83a4
        MAU type: 1000 BaseXFD
Link Aggregation TLV
        Aggregation capable
        Currently aggregated
        Aggregated Port ID: 491
Maximum Frame Size TLV
        9216
End of LLDPDU TLV
[root@backupsvr ~]#