Leif160519的blog Leif160519的blog

——————

目录
linux下怎么判断网卡速率
/  

linux下怎么判断网卡速率

本文摘自:https://blog.csdn.net/liugongfeng/article/details/50263733

我们都知道ifconfig -a 可以列出所有网卡,但是怎么判读是千兆网卡还是百兆网卡呢?

1. 判断是千兆网卡还是百兆网卡

ethtool <network interface> #查看支持的速率

若提示没有这个命令则安装

apt-get install ethtool

先列举出所有网卡信息

root@ubuntu:~# ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:2aff:feef:8940  prefixlen 64  scopeid 0x20<link>
        ether 02:42:2a:ef:89:40  txqueuelen 0  (以太网)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 18887  bytes 2080433 (2.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.81.208  netmask 255.255.254.0  broadcast 192.168.81.255
        inet6 fe80::c0b1:bc04:43a5:9eab  prefixlen 64  scopeid 0x20<link>
        ether f4:8e:38:ad:34:6d  txqueuelen 1000  (以太网)
        RX packets 14707617  bytes 2023491977 (2.0 GB)
        RX errors 0  dropped 878402  overruns 0  frame 0
        TX packets 14536172  bytes 10058264384 (10.0 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp3s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:e0:4c:99:22:51  txqueuelen 1000  (以太网)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (本地环回)
        RX packets 3621152  bytes 2568673549 (2.5 GB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3621152  bytes 2568673549 (2.5 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

使用ethtool命令查看该网卡的支持速率
image.png

虽然spee是1000mb/s了,但是还不能代表这就是一块千兆网卡,网卡速率和网线,交换机端口速率都有关系,看到Auto-negotiation字段了吧,on表示开启
自动协商,插上网线后会两端会自动协商一个都支持的速率;

2. Link detected 代表什么

以前就知道yes 表示网卡插好网线了(亮了),反过来呢?是不是插好网线就是yes
不是这样的,插好网线,还要激活网卡(ifup ethx, 其实是二层up)才会yes;

3. 一个类似命令mii-tool, 查看连接状态和速率

root@ubuntu:~# mii-tool enp2s0
enp2s0: negotiated 1000baseT-FD flow-control, link ok
root@ubuntu:~# mii-tool enp3s0
enp3s0: no link

问题来了,如果ethtool 和mii-tool查出来的速率不同呢?
曾经有个千兆网卡,二者查出的速率不同,多方查阅,终于在man mii-tool发现了结果
This program is obsolete. Valid media are only 100baseT4, 100baseTx-FD,100baseTx-HD, 10baseT-FD and 10baseT-HD ethernet cards. For replacement check ethtool.
如果你也遇到这个问题,不要犹豫,果断相信ethtool的结果吧。


“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill

标  题linux下怎么判断网卡速率
作  者Leif160519
出  处https://github.icu/articles/2019/09/16/1568615444884.html
关于博主:坐标南京,运维工程师,如有问题探讨可以直接下方留言。
声援博主:如果您觉得文章对您有帮助,可以评论、订阅、收藏。您的鼓励是博主的最大动力!