linux 网卡状态命令mii-tool 和 ethtool

96
faraway_com
2017.06.05 17:50* 字数 343

linux下用mii-tool和ethtool 查看网线是否正确连接到网卡
输入mii-tool可以查看网线是否连接到网卡

mii-tool

eth0: negotiated 100baseTx-FD, link ok

有时驱动可能不支持会出错下列错误

mii-tool

SIOCGMIIPHY on 'eth0' failed: Operation not supported
no MII interfaces found(用sudo su切换到超级管理员用户状态就可以用了。)

可以使用ethtool查看

ethtool eth0

Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: pumbg
        Wake-on: g
        Current message level: 0x00000033 (51)
        Link detected: yes

Link detected: yes为正常no为失败

mii-tool 的用法:
mii-tool 在更改网络设备通信协商方式的方法比较简单,用 -v 参数来查看网络接口的状态;看下面的例子;
mii-tool 更改网络接口协商的方法;
[root@localhost ~]# mii-tool --help
usage: mii-tool [-VvRrwl] [-A media,... | -F media] [interface ...]
-V, --version display version information
-v, --verbose more verbose output 注:显示网络接口的信息;
-R, --reset reset MII to poweron state 注:重设MII到开启状态;
-r, --restart restart autonegotiation 注:重启自动协商模式;
-w, --watch monitor for link status changes 注:查看网络接口连接的状态变化;
-l, --log with -w, write events to syslog 注:写入事件到系统日志;
-A, --advertise=media,... advertise only specified media 注:指令特定的网络接口;
-F, --force=media force specified media technology 注:更改网络接口协商方式;
media: 100baseT4, 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD,
(to advertise both HD and FD) 100baseTx, 10baseT

example:
[at_Neal:root:~:]# mii-tool
eth0: negotiated 100baseTx-FD flow-control, link ok
eth1: no link
eth2: negotiated 100baseTx-FD flow-control, link ok

Linux 基础