Linux-1-網絡1. lldp配置


摘取自:

centos配置lldp與交換機建立鄰居關系_achejq的專欄-CSDN博客

Linux之lldptool命令 - ReevesMeng - 博客園

有修改。

 

lldpad(lldpd)

centos上開啟lldp的程序為lldpad。ubuntu上為lldpd。

首先安裝:

yum install -y lldpad

如果主機不能聯網,可以掛載安裝光盤,並配置光盤yum源;或進入光盤下的package目錄,使用yum localinstall來安裝。

然后運行:

lldpad -d #或者systemctl start lldpad;

在所有接口開啟【可以復制到shell腳本中執行】

【grep可以這么寫:egrep 'em|eth|ens'】:

for i in `ls /sys/class/net/ | grep "em\|eth\|ens"` ;
    do echo "enabling lldp for interface: $i" ;
    lldptool set-lldp -i $i adminStatus=rxtx ;
    lldptool -T -i $i -V sysName enableTx=yes ;
    lldptool -T -i $i -V portDesc enableTx=yes ;
    lldptool -T -i $i -V sysDesc enableTx=yes ;
    lldptool -T -i $i -V sysCap enableTx=yes ;
    lldptool -T -i $i -V mngAddr ipv4=`hostname -I` ;
    lldptool -T -i $i -V mngAddr enableTx=yes ;
done

 

這樣交換機就可以發現了。

lldpad在服務器上有命令行調試工具:

lldptool get-tlv -n -i "interface"

Ubuntu要好用一些,直接有lldpcli命令行進行調試。

 

1. lldptool 描述

當我們想在操作系統里面查看網口和交換機連接的狀態信息,我們可以使用lldptool這個工具。

 

2. LLDP 協議

LLDP是一個數據鏈路層發現協議,LLDP協議使得接入網絡的一台設備可以將其主要的能力,管理地址,設備標識,接口標識等信息發送給接入同一個局域網絡的其它設備。lldptool工具采用的是LLDP協議,一般我們使用lldptool是為了得到設備的物理拓撲結構以及管理配置信息,比如說,和eth1網口相連的網絡交換機的Vlan ID是多少?網絡交換機的名稱是什么?網線插在網絡交換機的什么地方?

在這里我們不去討論LLDP協議的架構和具體時序狀態碼等,這里僅僅介紹怎么用它。

LLDP 協議有四種工作模式【adminStatus】:

  • TxRx:既發送也接收LLDP 幀
  • Tx:只發送不接收LLDP 幀
  • Rx:只接收不發送LLDP 幀
  • Disable:既不發送也不接收

 

一般設置LLDP工作在TxRx模式。

 

3. lldptool 的命令格式

[root@SJ-S-hlw-DB-Ser01 ~]# lldptool --help
Usage:
lldptool [options] [arg] general command line usage format
lldptool go into interactive mode
[options] [arg] general interactive command format

Options:
-i [ifname] network interface
-V [tlvid] TLV identifier
may be numeric or keyword (see below)
-c used with get TLV command to specify
that the list of configuration elements
should be retrieved
-d use to delete specified argument from
the configuration. (Currently
implemented for DCBX App TLV settings)
-n "neighbor" option for command
-r show raw message
-R show only raw messages
-g destination agent (may be one of):
- nearestbridge (nb) (default)
- nearestcustomerbridge (ncb)
- nearestnontpmrbridge (nntpmrb)

Commands:
license show license information
-h|help show command usage information
-v|version show version
-p|ping ping lldpad and query pid of lldpad
-q|quit exit lldptool (interactive mode)
-S|stats get LLDP statistics for ifname
-t|get-tlv get TLVs from ifname
-T|set-tlv set arg for tlvid to value
-l|get-lldp get the LLDP parameters for ifname
-L|set-lldp set the LLDP parameter for ifname

TLV identifiers:
chassisID : Chassis ID TLV
portID : Port ID TLV
TTL : Time to Live TLV
portDesc : Port Description TLV
sysName : System Name TLV
sysDesc : System Description TLV
sysCap : System Capabilities TLV
mngAddr : Management Address TLV
macPhyCfg : MAC/PHY Configuration Status TLV
powerMdi : Power via MDI TLV
linkAgg : Link Aggregation TLV
MTU : Maximum Frame Size TLV
LLDP-MED : LLDP-MED Settings
medCap : LLDP-MED Capabilities TLV
medPolicy : LLDP-MED Network Policy TLV
medLoc : LLDP-MED Location TLV
medPower : LLDP-MED Extended Power-via-MDI TLV
medHwRev : LLDP-MED Hardware Revision TLV
medFwRev : LLDP-MED Firmware Revision TLV
medSwRev : LLDP-MED Software Revision TLV
medSerNum : LLDP-MED Serial Number TLV
medManuf : LLDP-MED Manufacturer Name TLV
medModel : LLDP-MED Model Name TLV
medAssetID : LLDP-MED Asset ID TLV
CIN-DCBX : CIN DCBX TLV
CEE-DCBX : CEE DCBX TLV
evb : EVB Configuration TLV
evbcfg : EVB draft 0.2 Configuration TLV
vdp : VDP draft 0.2 protocol configuration
IEEE-DCBX : IEEE-DCBX Settings
ETS-CFG : IEEE 8021QAZ ETS Configuration TLV
ETS-REC : IEEE 8021QAZ ETS Recommendation TLV
PFC : IEEE 8021QAZ PFC TLV
APP : IEEE 8021QAZ APP TLV
PVID : Port VLAN ID TLV
PPVID : Port and Protocol VLAN ID TLV
vlanName : VLAN Name TLV
ProtoID : Protocol Identity TLV
vidUsage : VID Usage Digest TLV
mgmtVID : Management VID TLV
linkAggr : Link Aggregation TLV
uPoE : Cisco 4-wire Power-via-MDI TLV

ARGUMENTS【截取於man lldptool】
This section lists arguments which are available for administration of LLDP parameters. Arguments for basic TLV's (non-organizationally specific TLVs) are also described. See the SEE ALSO section for references to other lldptool man pages which contain usage details and arguments for various organizationally specific TLVs.
adminStatus:Argument for the get-lldp/set-lldp commands. Configures the LLDP adminStatus parameter for the specified interface. Valid values are: disabled, rx, tx, rxtx
enableTx:Argument for the get-tlv/set-tlv commands. May be applied per interface for a specified TLV. Valid values are: yes, no. If the DCBX TLV enableTx is set to no, then all of the DCB feature TLVs DCBX advertise settings will be turned off as well. Setting enableTx to yes will enable the DCBX advertise settings.
ipv4:Argument for the get-tlv/set-tlv commands with respect to the Management Address TLV. The get command will retrieve the configured value. Set values take the form of an IPv4 address: A.B.C.D
ipv6:Argument for the get-tlv/set-tlv commands with respect to the Management Address TLV. The get command will retrieve the configured value. Set values take the form of an IPv6 address: 1111:2222:3333:4444:5555:6666:7777:8888 and various shorthand variations.

 

4. lldptool 使用舉例

ip a查看啟用網口:

[root@SJ-S-hlw-DB-Ser01 ~]# ip add | grep "state UP"
2: ens4f0: mtu 1500 qdisc mq master bond0 state UP group default qlen 1000
4: ens5f0: mtu 1500 qdisc mq master bond0 state UP group default qlen 1000
50: bond0: mtu 1500 qdisc noqueue state UP group default qlen 1000
51: bond0.1501@bond0: mtu 1500 qdisc noqueue state UP group default qlen 1000

 

先看一些有沒有lldptool工具,如果沒有的話yum裝一下: 

[root@wow ~]# service lldpad status
lldpad is stopped

[root@wow ~]# service lldpad start
Starting lldpad: [ OK ]

 

先設置lldptool的工作模式:

[root@wow ~]# lldptool set-lldp -i eth0 adminStatus=rxtx

adminStatus = rxtx #這樣就和網絡交換機建立了鄰居關系,接下來就可以查詢連接的交換機信息了;

使用lldptool查看網口與交換機連接狀態:

[root@wow ~]# lldptool -tni eth0
Chassis ID TLV
MAC: 48:xx:xx:xx:xx:51 #mac地址
Port ID TLV
Ifname: GE1/0/1 #網線插在交換機上的端口位置
Time to Live TLV
120
System Name TLV
xx-xx-CE5850-xxxxx #交換機設備名
System Description TLV
Huawei Versatile Routing Platform Software
VRP (R) software, Version 8.150 (CE5855EI V200R002C50SPC800)
Copyright (C) 2012-2017 Huawei Technologies Co., Ltd.
HUAWEI CE5855-xxxx-xxx #華為的交換機

System Capabilities TLV
System capabilities: Bridge, Router
Enabled capabilities: Bridge, Router
Management Address TLV
IPv4: xx.xxx.xxx.xx #ip地址
Ifindex: 4
OID: +[)
Port VLAN ID TLV
PVID:
Port and Protocol VLAN ID TLV
PVID: 0, not supported, not enabled
VLAN Name TLV
VID 3652: Name VLAN3652
MAC/PHY Configuration Status TLV
Auto-negotiation supported and enabled
PMD auto-negotiation capabilities: 0xxxxx
MAU type: 1000 BaseXFD
Link Aggregation TLV
Aggregation capable
Currently not aggregated
Aggregated Port ID: 0
Maximum Frame Size TLV
9216
End of LLDPDU TLV

 

如果想利用lldptool對網口進行一些設置,可以參考手冊,下面是在Linux上找男人看到的一些例子: 

 

Configure LLDP adminStatus to Receive and Transmit for interface eth2   #為網口eth2配置LLDP的收發工作模式
lldptool -L -i eth2 adminStatus=rxtx
lldptool set-lldp -i eth2 adminStatus=rxtx 
Disable the LLDP adminStatus for all interfaces  #讓所有網口都不可用LLDP
lldptool set-lldp adminStatus=disabled
Query the LLDP adminStatus for interface eth3   #查詢網口eth3的LLDP狀態
lldptool -l -i eth3 adminStatus
lldptool get-lldp -i eth3 adminStatus 
Query the LLDP statistics for interface eth3    #查詢網口eth3的統計信息
lldptool -S -i eth3 adminStatus
lldptool stats -i eth3 adminStatus

Query the local TLVs which are being transmitted for a given interface:  #查詢為給定接口傳輸的本地
lldptool -t -i eth3
lldptool get-tlv -i eth3

Query the received neighbor TLVs received on a given interface:  #查詢給定接口上收到的接收鄰居TLV
lldptool -t -n -i eth3
lldptool get-tlv -n -i eth3

Query the value of the System Description TLV as received from the neighbor on a given interface:
lldptool -t -n -i eth3 -V sysDesc
lldptool get-tlv -n -i eth3 -V 6

Disable transmit of the IEEE 802.3 MAC/PHY Configuration Status TLV for a given interface:
lldptool -T -i eth3 -V macPhyCfg enableTx=no
lldptool set-tlv -i eth3 -V 0x120f01 enableTx=no 
Enable transmit of the Port Description TLV for all interfaces:
lldptool -T -V portDesc enableTx=yes
lldptool set-tlv -V 4 enableTx=yes

Query value of the transmit setting for the Port Description TLV for a given interface:
lldptool -t -V portDesc -c enableTx
lldptool get-tlv -V 4 -c enableTx 
Set a Management Address TLV on eth3 to carry IPv4 address 192.168.10.10
lldptool -T -i eth3 -V mngAddr ipv4=192.168.10.10
Set a Management Address TLV on eth3 to carry IPv6 address ::192.168.10.10
lldptool -T -i eth3 -V mngAddr ipv6=::192.168.10.10

Get the configured IPv4 address for the Management Address TLV on eth3
lldptool -t -i eth3 -V mngAddr -c ipv4
Get all configured attributes for the Management Address TLV on eth3
lldptool -t -i eth3 -V mngAddr -c
Query the current DCBX mode that will be used if lldpad is restarted. (this is not a persistent setting)
lldptool -t -i eth3 -V IEEE-DCBX -c mode 
Reset the DCBX mode to be 'auto' (start in IEEE DCBX mode) after the next lldpad restart
lldptool -T -i eth3 -V IEEE-DCBX mode=reset
Enable transmit of the Edge Virtual Bridging TLV for interface eth4
lldptool -i eth4 -T -V evbCfg enableTx=yes

Configure EVB TLV to set reflective relay and RTE,ECP and VDP capabilities
lldptool -T -i eth4 -V evbCfg fmode=reflectiverelay
lldptool -T -i eth4 -V evbCfg capabilities=rte,ecp,vdp 
Enable transmit of the VDP for interface eth4
lldptool -i eth4 -T -V vdp enableTx=yes
Configurations per port have higher precedence than global configurations.

 

# #

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM