1. 描述

当我们想在操作系统里面查看网口和交换机连接的状态信息,我们可以使用lldptool这个工具。

2.LLDP协议

LLDP是一个数据链路层发现协议,LLDP协议使得接入网络的一台设备可以将其主要的能力,管理地址,设备标识,接口标识等信息发送给接入同一个局域网络的其它设备。lldptool工具采用的是LLDP协议,一般我们使用lldptool是为了得到设备的物理拓扑结构以及管理配置信息,比如说,和eth1网口相连的网络交换机的Vlan ID是多少?网络交换机的名称是什么?网线插在网络交换机的什么地方?

在这里我们不去讨论LLDP协议的架构和具体时序状态码等,这里仅仅介绍怎么用它。

LLDP协议有四种工作模式:

  • TxRx:既发送也接收LLDP 帧
  • Tx    :只发送不接收LLDP 帧
  • Rx:只接收不发送LLDP 帧
  • Disable:既不发送也不接收

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

3.lldptool的命令格式

lldptool <command> [options] [参数]

Options

-i [ifname]
specifies the network interface to which the command applies
-V [tlvid]
specifies the TLV identifier
The tlvid is an integer value used to identify specific LLDP TLVs. The tlvid value is the Type value for types not equal to 127 (the organizationally specific type). For organizationally specific TLVs, the tlvid is the value represented by the 3 byte OUI and 1 byte subtype - where the subtype is the lowest order byte of the tlvid.
The tlvid can be entered as a numerical value (e.g. 10 or 0xa), or for supported TLVs, as a keyword. Review the lldptool help output to see the list of supported TLV keywords.
-n
"neighbor" option for commands which can use it (e.g. get-tlv)
-g [bridge scope]
specify the bridge scope this command operates on. Allows to set and query all LLDP TLV modules for "nearest_bridge" (short: "nb"), "nearest_customer_bridge" ("ncb") and "nearest_nontpmr_bridge" ("nntpmrb") group mac addresses. Configurations are saved into independent sections in lldpad.conf. If no bridge scope is supplied this default to "nearest bridge" to preserve the previous behaviour.
-c <argument list>
"config" option for TLV queries. Indicates that the query is for the configuration elements for the specified TLV. The argument list specifies the specific elements to query. If no arguments are listed, then all configuration elements for the TLV are returned.
-r
show raw client interface messages
-R
show only raw Client interface messages

Commands

license
show license information
-h, help
show usage information
-v, version
show version information
-S, stats
get LLDP statistics
-t, get-tlv
get TLV information
-T, set-tlv
set TLV information
-l, get-lldp
get LLDP parameters
-L, set-lldp
set LLDP parameters
-q, quit
exit from interactive mode

4.lldptool使用举例

ip a查看启用网口:

先看一些有没有lldptool工具,如果没有的话yum装一下:

  1. [root@wow ~]# service lldpad status
  2. lldpad is stopped
  3. [root@wow ~]# service lldpad start
  4. Starting lldpad: [ OK ]
  5. [root@wow ~]#

先设置lldptool的工作模式:

  1. [root@wow ~]# lldptool set-lldp -i eth0 adminStatus=rxtx
  2. adminStatus = rxtx  #这样就和网络交换机建立了邻居关系,接下来就可以查询连接的交换机信息了

使用lldptool查看网口与交换机连接状态:

  1. [root@wow ~]# lldptool -t -n -i eth0
  2. Chassis ID TLV
  3. MAC: :xx:xx:xx:xx:51  #mac地址
  4. Port ID TLV
  5. Ifname: GE1//1    #网线插在交换机上的端口位置
  6. Time to Live TLV
  7.  
  8. System Name TLV
  9. xx-xx-CE5850-xxxxx  #交换机设备名
  10. System Description TLV
  11. Huawei Versatile Routing Platform Software
  12. VRP (R) software, Version 8.150 (CE5855EI V200R002C50SPC800)
  13. Copyright (C) - Huawei Technologies Co., Ltd.
  14. HUAWEI CE5855-xxxx-xxx  #华为的交换机
  15.  
  16. System Capabilities TLV
  17. System capabilities: Bridge, Router
  18. Enabled capabilities: Bridge, Router
  19. Management Address TLV
  20. IPv4: xx.xxx.xxx.xx  #ip地址
  21. Ifindex:
  22. OID: +[)
  23. Port VLAN ID TLV
  24. PVID:
  25. Port and Protocol VLAN ID TLV
  26. PVID: , not supported, not enabled
  27. VLAN Name TLV
  28. VID : Name VLAN3652
  29. MAC/PHY Configuration Status TLV
  30. Auto-negotiation supported and enabled
  31. PMD auto-negotiation capabilities: 0xxxxx
  32. MAU type: BaseXFD
  33. Link Aggregation TLV
  34. Aggregation capable
  35. Currently not aggregated
  36. Aggregated Port ID:
  37. Maximum Frame Size TLV
  38.  
  39. End of LLDPDU TLV
  40. [root@wow ~]#

如果想利用lldptool对网口进行一些设置,可以参考手册,下面是在Linux上找男人看到的一些例子:

  1. Configure LLDP adminStatus to Receive and Transmit for interface eth2  #为网口eth2配置LLDP的收发工作模式
  2. lldptool -L -i eth2 adminStatus=rxtx
  3. lldptool set-lldp -i eth2 adminStatus=rxtx
  4.  
  5. Disable the LLDP adminStatus for all interfaces  #让所有网口都不可用LLDP
  6. lldptool set-lldp adminStatus=disabled
  7. Query the LLDP adminStatus for interface eth3  #查询网口eth3的LLDP状态
  8. lldptool -l -i eth3 adminStatus
  9. lldptool get-lldp -i eth3 adminStatus
  10.  
  11. Query the LLDP statistics for interface eth3   #查询网口eth3的统计信息
  12. lldptool -S -i eth3 adminStatus
  13. lldptool stats -i eth3 adminStatus
  14.  
  15. Query the local TLVs which are being transmitted for a given interface:   #查询为给定接口传输的本地
  16. lldptool -t -i eth3
  17. lldptool get-tlv -i eth3
  18.  
  19. Query the received neighbor TLVs received on a given interface:  #查询给定接口上收到的接收邻居TLV
  20. lldptool -t -n -i eth3
  21. lldptool get-tlv -n -i eth3
  22.  
  23. Query the value of the System Description TLV as received from the neighbor on a given interface:
  24. lldptool -t -n -i eth3 -V sysDesc
  25. lldptool get-tlv -n -i eth3 -V
  26.  
  27. Disable transmit of the IEEE 802.3 MAC/PHY Configuration Status TLV for a given interface:
  28. lldptool -T -i eth3 -V macPhyCfg enableTx=no
  29. lldptool set-tlv -i eth3 -V 0x120f01 enableTx=no
  30.  
  31. Enable transmit of the Port Description TLV for all interfaces:
  32. lldptool -T -V portDesc enableTx=yes
  33. lldptool set-tlv -V enableTx=yes
  34.  
  35. Query value of the transmit setting for the Port Description TLV for a given interface:
  36. lldptool -t -V portDesc -c enableTx
  37. lldptool get-tlv -V -c enableTx
  38.  
  39. Set a Management Address TLV on eth3 to carry IPv4 address 192.168.10.10
  40. lldptool -T -i eth3 -V mngAddr ipv4=192.168.10.10
  41. Set a Management Address TLV on eth3 to carry IPv6 address ::192.168.10.10
  42. lldptool -T -i eth3 -V mngAddr ipv6=::192.168.10.10
  43.  
  44. Get the configured IPv4 address for the Management Address TLV on eth3
  45. lldptool -t -i eth3 -V mngAddr
  46. -
  47.  
  48. c ipv4
  49.  
  50. Get all configured attributes for the Management Address TLV on eth3
  51. lldptool -t -i eth3 -V mngAddr -c
  52. Query the current DCBX mode that will be used if lldpad is restarted. (this is not a persistent setting)
  53. lldptool
  54. -
  55.  
  56. t -i eth3 -V IEEE-DCBX -c mode
  57.  
  58. Reset the DCBX mode to be 'auto' (start in IEEE DCBX mode) after the next lldpad restart
  59. lldptool -T -i eth3 -V IEEE-DCBX mode=reset
  60. Enable transmit of the Edge Virtual Bridging TLV for interface eth4
  61. lldptool
  62. -
  63.  
  64. i eth4 -T -V evbCfg enableTx=yes
  65.  
  66. Configure EVB TLV to set reflective relay and RTE,ECP and VDP capabilities
  67. lldptool -T -i eth4 -V evbCfg fmode=reflectiverelay
  68. lldptool -T -i eth4 -V evbCfg capabilities=rte,ecp,vdp
  69.  
  70. Enable transmit of the VDP for interface eth4
  71. lldptool -i eth4 -T -V vdp enableTx=yes
  72. Configurations per port have higher precedence than global configurations.

Linux之lldptool命令的更多相关文章

  1. Linux下history命令用法

    如果你经常使用 Linux 命令行,那么使用 history(历史)命令可以有效地提升你的效率.本文将通过实例的方式向你介绍 history 命令的 15 个用法. 使用 HISTTIMEFORMAT ...

  2. Linux下ps命令详解 Linux下ps命令的详细使用方法

    http://www.jb51.net/LINUXjishu/56578.html Linux下的ps命令比较常用 Linux下ps命令详解Linux上进程有5种状态:1. 运行(正在运行或在运行队列 ...

  3. 例解 Linux 下 Make 命令

    Linux 下 make 命令是系统管理员和程序员用的最频繁的命令之一.管理员用它通过命令行来编译和安装很多开源的工具,程序员用它来管理他们大型复杂的项目编译问题.本文我们将用一些实例来讨论 make ...

  4. Linux终端打印命令使用介绍

    常用linux打印命令 日常使用中或shell脚本中linux终端打印命令有echo和printf.  echo命令 功能说明:显示文字.语 法:echo [-ne][字符串]或 echo [--he ...

  5. linux常用的命令

    Linux简介及Ubuntu安装 Linux,免费开源,多用户多任务系统.基于Linux有多个版本的衍生.RedHat.Ubuntu.Debian 安装VMware或VirtualBox虚拟机.具体安 ...

  6. 查看linux系统版本命令 (转)

    查看linux系统版本命令 分类: Linux 知识小结2011-10-10 15:26 240162人阅读 评论(9) 收藏 举报 linuxredhatdebianx86susesun 一.查看内 ...

  7. linux入门级常用命令

    1) 关闭Linux系统的命令:init 02) Linux终端:Linux终端也称为虚拟控制台.Linux终端采用字符命令行方式工作,用户通过键盘输入命令,通过Linux终端对系统进行控制.3) 切 ...

  8. linux之find命令详解

    linux之find命令详解 查找文件find ./ -type f查找目录find ./ -type d查找名字为test的文件或目录find ./ -name test查找名字符合正则表达式的文件 ...

  9. 12个Linux进程管理命令介绍(转)

    12个Linux进程管理命令介绍 [日期:2015-06-02] 来源:Linux中国  作者:Linux [字体:大 中 小]   执行中的程序在称作进程.当程序以可执行文件存放在存储中,并且运行的 ...

随机推荐

  1. Windows下安装Scrapy方法及常见安装问题总结——Scrapy安装教程

    这几天,很多朋友在群里问Scrapy安装的问题,其实问题方面都差不多,今天小编给大家整理一下Scrapy的安装教程,希望日后其他的小伙伴在安装的时候不再六神无主,具体的教程如下. Scrapy是Pyt ...

  2. echarts 总结:

    options配置项: title: 图表标题的配置 tooltip: 鼠标悬浮的提示 toolbox: 工具栏 series: 数据项,是每一个个的数据对象,可以根据type配置每一项数据的图例. ...

  3. 【J-meter】调试JDBC请求

    参考资料: http://www.codesec.net/view/165234.html

  4. Redis序列化存储Java集合List等自定义类型

    在"Redis学习总结和相关资料"http://blog.csdn.net/fansunion/article/details/49278209 这篇文章中,对Redis做了总体的 ...

  5. IDEA使用GIT 上传到GitHub

    1.下载Git https://www.git-scm.com/download/ 2.安装 3.IDEA配置Git(设置Git路径,点击Test),如下代表成功 4.创建仓库 5.add 6.pus ...

  6. python3+opencv+tkinter开发简单的人脸识别小程序

    学校里有门图像处理的课程最终需要提交一个图像处理系统, 正好之前对于opencv有些了解,就简单的写一个人脸识别小程序吧 效果图如下 笔者IDE使用Pycharm,GUI编程直接使用内置的tkinte ...

  7. 【转】C#中RSA加密解密和签名与验证的实现

    [转]C#中RSA加密解密和签名与验证的实现 RSA加密算法是一种非对称加密算法.在公钥加密标准和电子商业中RSA被广泛使用.RSA是1977年由罗纳德•李维斯特(Ron Rivest).阿迪•萨莫尔 ...

  8. 洛谷 P1952 火星上的加法运算_NOI导刊2009提高(3)

    P1952 火星上的加法运算_NOI导刊2009提高(3) 题目描述 最近欢欢看到一本有关火星的书籍,其中她被一个加法运算所困惑,由于她的运算水平有限.她想向你求助,作为一位优秀的程序员,你当然不会拒 ...

  9. 洛谷 P3199 [HNOI2009]最小圈

    P3199 [HNOI2009]最小圈 题目背景 如果你能提供题面或者题意简述,请直接在讨论区发帖,感谢你的贡献. 题目描述 对于一张有向图,要你求图中最小圈的平均值最小是多少,即若一个圈经过k个节点 ...

  10. Consolas 字体

    Consolas是一套等宽字体的字型,属无衬线字体,由Lucas de Groot设计. 概述 这套字型使用了微软的ClearType 字型平滑技术,并随同Windows Vista.Office 2 ...