转自:https://www.cnblogs.com/kelamoyujuzhen/p/10116423.html

参考:9 Linux ethtool Examples to Manipulate Ethernet Card (NIC Card)

Fun with ethtool

简介

ethtool允许你修改Ethernet adapter配置,并且这种修改只适用于physical ethernet adapters,这意味着bond0,tun0和任何其他非物理网络设备将无法与ethtool一起使用。

注意:大多数Linux内核将以太网设备标记为ethX,其中X是物理以太网接口的#(从0开始)。

我知道我知道,先从最少使用的东西开始。 但是,嘿,有人可能觉得这很有用,对吗? 在处理内核级别问题时,我可能不得不在10年以上查询驱动程序信息十几次,但有人必须在他们生命中的某个时刻遇到这个问题,让我告诉你,它可能更容易 运行一个命令,而不是通过lsmod挖掘并希望模块正确地拾取驱动程序。

驱动信息 和 统计数据

在处理内核级别的问题时,人们往往会使用lsmod来查看相应驱动是否被加载,使用ethtool可以更优雅的解决这个问题。

-i:Queries the specified network device for associated driver information.

root@ubuntu:~# ethtool -i ens32
driver: e1000
version: 7.3.21-k8-NAPI
firmware-version:
expansion-rom-version:
bus-info: 0000:02:00.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no

-S(大写):Queries the specified network device for NIC- and driver-spe‐cific statistics.

这个参数可以快速定位 rx/tx问题

root@ubuntu:~# ethtool -S ens32
NIC statistics:
rx_packets: 380
tx_packets: 386
rx_bytes: 42819
tx_bytes: 81789
rx_broadcast: 0
tx_broadcast: 0
rx_multicast: 0
tx_multicast: 0
rx_errors: 0
tx_errors: 0
tx_dropped: 0
multicast: 0
collisions: 0
rx_length_errors: 0
rx_over_errors: 0
rx_crc_errors: 0
rx_frame_errors: 0
rx_no_buffer_count: 0
rx_missed_errors: 0
tx_aborted_errors: 0
tx_carrier_errors: 0
tx_fifo_errors: 0
tx_heartbeat_errors: 0
tx_window_errors: 0
tx_abort_late_coll: 0
tx_deferred_ok: 0
tx_single_coll_ok: 0
tx_multi_coll_ok: 0
tx_timeout_count: 0
tx_restart_queue: 0
rx_long_length_errors: 0
rx_short_length_errors: 0
rx_align_errors: 0
tx_tcp_seg_good: 1
tx_tcp_seg_failed: 0
rx_flow_control_xon: 0
rx_flow_control_xoff: 0
tx_flow_control_xon: 0
tx_flow_control_xoff: 0
rx_long_byte_count: 42819
rx_csum_offload_good: 358
rx_csum_offload_errors: 0
alloc_rx_buff_failed: 0
tx_smbus: 0
rx_smbus: 0
dropped_smbus: 0

跟踪网卡

当一台服务器上有多张网卡,查找具体某一张物理网卡往往十分令人头疼。当然,你可以这么做:从ifconfig中取出MAC地址,将所有电缆插入一个管理型交换机,然后在交换机上将Mac表导出,查看具体Mac指向哪里。 使用ethtool可以更优雅地解决这个问题。

-p:Initiates adapter-specific action intended to enable an oper‐ator to easily identify the adapter by sight. Typically this involves blinking one or more LEDs on the specific network port.

ethtool -p ethX [N] 

其中[N]是闪烁的秒数。 ethtool -p eth0 15使eth0闪烁15秒。此时,太网适配器背面的指示灯闪烁会闪烁。

测试Ethernet Adapter

可以针对物理以太网接口运行一些基本测试,测试有两个选项,一个online test(tests nvram and a link test)和一个offline test(register, memory, loopback, interrupt)。 脱机测试很可能在测试期间使主机离线,因此如果你对生产服务器或只能远程访问的计算机运行此操作,请特别注意。

ethtool -t ethX [offline|online] 
root@ubuntu:~# ethtool -t ens32 online
The test result is PASS
The test extra info:
Register test (offline) 0
Eeprom test (offline) 0
Interrupt test (offline) 0
Loopback test (offline) 0
Link test (on/offline) 0 root@ubuntu:~# ethtool -t ens32 offline
The test result is FAIL
The test extra info:
Register test (offline) 0
Eeprom test (offline) 0
Interrupt test (offline) 0
Loopback test (offline) 13
Link test (on/offline) 0

一些网卡可能不支持online test 或者 offline test

改变Ethernet 配置

ethtool ethX

检查网卡配置信息

root@ubuntu:~# ethtool ens32
Settings for ens32:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
    partner advertised link modes:	10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Link partner advertised pause frame use: No
Link partner advertised auto-negotiation: Yes
    Speed: 1000Mb/s 
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
MDI-X: off (auto)
Supports Wake-on: d
Wake-on: d
Current message level: 0x00000007 (7) drv probe link
Link detected: yes

可以得出结论:设备支持TP,最高1000BaseT/Full,自动协商。 Partner(Switch)支持最高100baseT / Full和自动协商。设备的实际设置:100Mb / s,全双工,运行TP,物理地址0,设置为自动协商,启用WoL并检测链路。

如果我网卡的支持链接模式设置为low(例如10/Half由于某种原因)但交换机支持1000baseT / Full,那么可以使用ethtool -s ethX将我的以太网设置更改为1000baseT / Full。几乎所有你看到的东西:ethtool ethX,可以用ethtool -s ethX改变。在这种情况下,您将使用以下内容:

ethtool -S eth0 speed 1000 duplex full autoneg on

 -s(小写):Allows changing some or all settings of the specified network device. All following options only apply if -s was specified.

Linux命令——ethtool的更多相关文章

  1. LINUX命令之ETHTOOL用法详解

    转载:http://crazyming.blog.51cto.com/1048571/738022 debian 下安装: sudo apt-get install ethtool 或者下载源码编译: ...

  2. (转)Linux命令之Ethtool用法详解

    Linux命令之Ethtool用法详解 原文:http://www.linuxidc.com/Linux/2012-01/52669.htm Linux/Unix命令之Ethtool描述:Ethtoo ...

  3. Linux命令整理中...

    Linux命令整理中... 最常用命令(我最近最常用的一般放在前面tipsbychsry) clear 清屏 date 显示日期 cal 显示日历 cal 2014 显示2014年的日历 shutdo ...

  4. Linux 命令小记

    1. pidof 进程名 :获取进程的pid,例如 pidof memcached 得到5333 2. unset Shell变量 :取消设置一个shell变量,从内存和shell的导出环境中删除它, ...

  5. 运维工程师必会的109个Linux命令

    运维工程师必会的109个Linux命令 版本1.0 崔存新 更新于2009-12-26 目录 1 文件管理 6 1.1 basename 6 1.2 cat 6 1.3 cd 7 1.4 chgrp ...

  6. Linux命令行技巧

    Linux命令行技巧 命令 描述 • apropos whatis 显示和word相关的命令. 参见线程安全 • man -t man | ps2pdf - > man.pdf 生成一个PDF格 ...

  7. 运维必须掌握的150个Linux命令

    线上查询及帮助命令(1个)man 目录操作命令(6个)ls tree pwd mkdir rmdir cd 文件操作命令(7个)touch cp mv rm ln find rename 文件查看及处 ...

  8. linux 命令中英文对照,收集

    linux 命令中英文对照,收集   linux 命令英文全文 Is Linux CLI case-sensitive? The answer is, yes. If you try to run L ...

  9. 这些Linux命令,让你的工作事半功倍!

    这些Linux命令,让你的工作事半功倍! 最近都在和Linux打交道,感觉还不错.我觉得Linux相比windows比较麻烦的就是很多东西都要用命令来控制,当然,这也是很多人喜欢linux的原因,比较 ...

随机推荐

  1. PyQt5-TableWidget 表格视图

    基于PyQt5 postgreSQL实现简单的数据插入.数据表格查询. 运行前需要安装psycopg2 模块,配置好postgerSQL. 先看效果图: 第1列为日期时间.第2列为自增1的编号.第3到 ...

  2. mean shift聚类算法的MATLAB程序

    mean shift聚类算法的MATLAB程序 凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 1. mean shift 简介 mean shift, 写的 ...

  3. 训练自己数据-xml文件转voc格式

    首先我们有一堆xml文件 笔者是将mask-rcnn得到的json标注文件转为xml的 批量json转xml方法:https://www.cnblogs.com/bob-jianfeng/p/1112 ...

  4. 【Eureka篇三】EurekaServer服务注册中心(1)

    注:在前面[Rest微服务案例(二)]的基础上进行操作. 1. 新建Maven Module,子模块名称为microservicecloud-eureka-7001,packaging为jar模式 & ...

  5. 详解C++ STL set 容器

    详解C++ STL set 容器 本篇随笔简单介绍一下\(C++STL\)中\(set\)容器的使用方法及常见使用技巧. set容器的概念和性质 \(set\)在英文中的意义是:集合.\(set\)容 ...

  6. Django cache (缓存)

    五种配置 1.开发调试 # 此为开始调试用,实际内部不做任何操作 # 配置: CACHES = { 'default': { 'BACKEND': 'django.core.cache.backend ...

  7. Django CSRF

    CSRF(Cross-site request forgery)跨站请求伪造 django为用户实现防止跨站请求伪造的功能,通过中间件 django.middleware.csrf.CsrfViewM ...

  8. 【day09】PHP

    一.函数 1. 作用域(Scope) (1)局部变量:变量在声明的代码段中有效 a.动态变量 b.静态变量:static ,用在函数中,当调用函数后内存不释放,能存储变量的最后的值. (2)全局变量: ...

  9. 将mysql主键id从1开始 变为自增

    在变为自增前,为了保证数据的安全性我们先将表中的数据备份一份,备份是通过mysql命令进行备份,如果已经安装mysql可视化工具navicat也可右键完成备份 1.备份表结构 create table ...

  10. 对flutter中,ExpsionPanel的简单改造

    因为项目有大量的下拉面板,而默认的组件(默认的padding.颜色.大小)不是我们UI设计上想要的,但是每个地方都要去改又很麻烦.于是我就想,可以对这个组件进行定制化改造,传入一些颜色.参数.图标大小 ...