linux下如何查看设置网卡速度--ethtool

本文介绍了在Linux环境下利用ethtool工具查看和管理网卡速度的方法,包括查询网卡信息、驱动和统计信息。通过ethtool可以了解网卡的物理接口类型、连接模式、自动协商状态、当前速度和双工模式等关键信息,确保网络连接的稳定和高效。

linux下如何查看网卡速度

使用内核自带的工具 ethtool 可以查看和设置网卡的网速

1.ethtool的基本用法

ethtool ethX      #查询ethX网口基本设置
ethtool –h        #显示ethtool的命令帮助(help)
ethtool –i ethX    #查询ethX网口的相关信息
ethtool –d ethX    #查询ethX网口注册性信息
ethtool –r ethX    #重置ethX网口到自适应模式
ethtool –S ethX    #查询ethX网口收发包统计
ethtool –s ethX [speed 10|100|1000]\         #设置网口速率10/100/1000M
[duplex half|full]\           #设置网口半/全双工
[autoneg on|off]\            #设置网口是否自协商
[port tp|aui|bnc|mii]\         #设置网口类型
[phyad N]\                
[xcvr internal|exteral]\
[wol p|u|m|b|a|g|s|d...]\
[sopass xx:yy:zz:aa:bb:cc]\
[msglvl N]

2.使用ethtool查询网卡信息


# 先查询网络设备名
> ifconfig -a       #查询全部网络设备

ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.136.205  netmask 255.255.255.0  broadcast 192.168.136.255
        inet6 fe80::fd2e:62ff:920a:1bd4  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ca:f5:45  txqueuelen 1000  (Ethernet)
        RX packets 3  bytes 729 (729.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 30  bytes 2102 (2.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
# 查询设备的信息
> ethtool  ens37

Settings for ens37:
        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
        Supported FEC modes: Not reported
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        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

我们来解释下看到的信息:

  • Supported ports :指支持的物理接口,这里仅包含TP 还可以有 Mii和 FIBRE 等类型。TP是指 双绞线(twisted pair)
  • link modes :指连接模式,其实这是用两个参数组合构成的速度(speed)和双工(Duplex)
modespeed(Mb/s)deplex
10baseT/Half10half
10baseT/Full10full
100baseT/Hal100half
100baseT/Full100full
1000baseT/Full1000full

half 指 半双工; ful指全双工

  • Auto-negotiation :自动协商,有一个很值得思考的问题,千兆网卡就一定会跑千兆的速度吗?不一定。这个选项就是可以网线两端的网络设备相互协商来确定其运行模式(on就是开启)
  • Speed 当前网卡设置的速度
  • Duplex 当前网卡设置的双工模式
  • Port 当前网卡连接的物理接口
  • Link detected: 表示当前的连接状况 yes 就是连通

3.使用ethtool查询网卡驱动

# 查询驱动
> ethtool -i ens37

driver: e1000
version: 7.3.21-k8-NAPI
firmware-version:
expansion-rom-version:
bus-info: 0000:02:05.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no

> modinfo  e1000
filename:       /lib/modules/3.10.0-1127.el7.x86_64/kernel/drivers/net/ethernet/intel/e1000/e1000.ko.xz
version:        7.3.21-k8-NAPI
license:        GPL
description:    Intel(R) PRO/1000 Network Driver
author:         Intel Corporation, <linux.nics@intel.com>
retpoline:      Y
rhelversion:    7.8
srcversion:     BED5FAF40AE66C5A4A6AC4C
alias:          pci:v00008086d00002E6Esv*sd*bc*sc*i*
alias:          pci:v00008086d000010B5sv*sd*bc*sc*i*
... ...

4.使用ethtool查询网卡统计信息

# 查询驱动
> ethtool -S ens37

NIC statistics:
     rx_packets: 23
     tx_packets: 32
     rx_bytes: 2622
     tx_bytes: 2274
     rx_broadcast: 0
     tx_broadcast: 0
... ...
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值