改变网络接口速度和协商方式miitool和ethtool

26 篇文章 0 订阅

refer to: http://blog.chinaunix.net/uid-793704-id-2545641.html

1、mii-tool 配置网络设备协商方式的工具;

  1.1 mii-tool 介绍;
  mii-tool - view, manipulate media-independent interface status (mii-tool 是查看,管理介质的网络接口的状态)
  有时网卡需要配置协商方式 ,比如10/100/1000M的网卡半双工、全双工、自动协商的配置。但大多数的网络设备是不用我们来修改协商,因为大多数网络设置接入的时候,都采用自动协商来解决相互通信的问题。不过自动协商也不是万能的,有时也会出现错误,比如丢包率比较高,这时就要我们来指定网卡的协商方式 。
  mii-tool 就是能指定网卡的协商方式。下面我们说一说mii-tool的用法;
  1.2 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
* 实例一:查看网络接口的协商状态;
  [root@localhost ~]# mii-tool -v eth0
  eth0: negotiated 100baseTx-FD, link ok
  product info: vendor 00:00:00, model 0 rev 0
  basic mode: autonegotiation enabled
  basic status: autonegotiation complete, link ok
  capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
  advertising: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
  link partner: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control
  注:上面的例子,我们可以看得到是自动协商。注意红字的部份;
* 实例二:更改网络接口协商方式;
  更改网络接口的协商方式,我们要用到-F选项,后面可以接 100baseT4, 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD等参数;
  如果我们想把网络接口eth0改为 1000Mb/s全双工的模式应该怎么办呢?
  [root@localhost ~]# mii-tool -F 100baseTx-FD
  [root@localhost ~]#mii-tool -v eth0
  eth0: 100 Mbit, full duplex, link ok
  product info: vendor 00:00:00, model 0 rev 0
  basic mode: 100 Mbit, full duplex
  basic status: link ok
  capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
  advertising: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
  注:是不是已经改过来了?当然,我们也一样用ethtool 工具来更改,比如执行下面的命令;
  [root@localhost ~]# ethtool -s eth0 speed 100 duplex full
2、ethtool 工具关于网络协商功能介绍;
  ethtool - Display or change ethernet card settings(ethtool 是用来显示和更改网卡设置的工具);这个工具比较复杂,功能也特别多。由于洋文比较难懂。所以我们还是把网络设备协商方式的设置方法说一说。
  2.1 ethtool 显示网络端口设置功能;
  这个功能比较好办。就是ethtool 后面直接接网絽接口就行;比如下面的例子;
  [root@localhost ~]# ethtool eth0
  Settings for eth0:
  Supported ports: [ TP MII ]
  Supported link modes: 10baseT/Half 10baseT/Full
  100baseT/Half 100baseT/Full
  Supports auto-negotiation: Yes
  Advertised link modes: 10baseT/Half 10baseT/Full
  100baseT/Half 100baseT/Full
  Advertised auto-negotiation: No 注:自动协商关闭
  Speed: 100Mb/s 注:速度 100Mb
  Duplex: Full 注:全双工
  Port: MII
  PHYAD: 32
  Transceiver: internal
  Auto-negotiation: off
  Supports Wake-on: pumbg
  Wake-on: d
  Current message level: 0x00000007 (7)
  Link detected: yes 注:eth0已经激活;
  2.2 ethtool 设置网卡的协商模式;
  在ethtool的-h帮助中我们查看到有这样的帮助信息;
  ethtool -s DEVNAME [ speed 10|100|1000 ] [ duplex half|full ] [ port tp|aui|bnc|mii|fibre ] [ autoneg on|off ]
* 实例一: 把网卡eth0 速度改为10Mb/s,采用半双工;
  [root@cuc03 beinan]# ethtool -s eth1 speed 10 duplex half
  [root@cuc03 beinan]# ethtool eth1
  Settings for eth1:
  Supported ports: [ TP MII ]
  Supported link modes: 10baseT/Half 10baseT/Full
  100baseT/Half 100baseT/Full
  Supports auto-negotiation: Yes
  Advertised link modes: 10baseT/Half 10baseT/Full
  100baseT/Half 100baseT/Full
  Advertised auto-negotiation: No
  Speed: 10Mb/s 注:速度 10M/s
  Duplex: Half 注:半双工
  Port: MII
  PHYAD: 32
  Transceiver: internal
  Auto-negotiation: off
  Supports Wake-on: pumbg
  Wake-on: d
  Current message level: 0x00000007 (7)
  Link detected: no 注:eth1没有激活;
* 实例二: 把网卡eth0 速度改为100Mb/s,采用全双工;
  [root@cuc03 beinan]# ethtool -s eth1 speed 100 duplex full
  [root@cuc03 beinan]# ethtool eth1
  Settings for eth1:
  Supported ports: [ TP MII ]
  Supported link modes: 10baseT/Half 10baseT/Full
  100baseT/Half 100baseT/Full
  Supports auto-negotiation: Yes
  Advertised link modes: 10baseT/Half 10baseT/Full
  100baseT/Half 100baseT/Full
  Advertised auto-negotiation: No
  Speed: 100Mb/s 注:速度 100M/s
  Duplex: Full 注:全双工
  Port: MII
  PHYAD: 32
  Transceiver: internal
  Auto-negotiation: off
  Supports Wake-on: pumbg
  Wake-on: d
  Current message level: 0x00000007 (7)
  Link detected: no 注:eth1网卡没有激活;
3、关于本文;
  本文是限定在改变网络协商方式和改变网络接口的速度为范围而写的
 
 
==============================================
Linux下修改网卡工作模式:
方法1:用ethtool命令。
查看当前的工作模式
ethtool eth0
设置成百兆全双工,关闭自适应
ethtool -s eth0 speed 100 duplex full autoneg off

方法2:
1. 查看网卡的工作模式,输入命令:
#mii-tool -v
  eth0: negotiated 100baseTx-FD,link ok
  product info:Vendor 00:05:be,model 8 rev 0
  basic status: autonegotiation complete,link ok
  basic mode:autonegotiation enabled.
  Capabilities: ..............
从以上信息中可以看出,这块网卡工作在100M全双工自适应模式下,“100BaseTx-FD”意为100M Full Duplex。
2. 更改网卡的工作模式,输入命令:
#mii-tool -F media [interface]
  media可选的模式有100baseTx-FD、100baseTx-HD、10baseT-FD、10baseT-HD等。 Interface代表所选择的网卡,如eth0、eth1等,默认为eth0。
例如,设置网卡工作在10M半双工模式下,输入命令:
#mii-tool -F 10baseT-HD eth0
3. 恢复网卡的自适应工作模式,输入命令:
#mii-tool -r eth0
  更详细的使用方法可以用mii-tool -h来获得。
 
====================================
描述:
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]
举例:
1)[root@linux /]# ethtool eth1
   Settings for eth1:
        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: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: umbg
        Wake-on: d
        Link detected: yes
2)[root@linux /]# ethtool -i eth1
   driver: e1000
   version: 5.0.43-k1
   firmware-version: N/A
   bus-info: 06:08.1
3)[root@linux /]# ethtool -S eth1
   NIC statistics:
     rx_packets: 58068300
     tx_packets: 87124083
     rx_bytes: 1589713008
     tx_bytes: 2165825901
     rx_errors: 0
     tx_errors: 0
     rx_dropped: 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_fifo_errors: 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
4)[root@linux /]# ethtool -s eth1 autoneg off speed 100 duplex full
相关:
1)[root@linux /]# which ethtool
    /sbin/ethtool
2)[root@linux /]# rpm -qf /sbin/ethtool
   ethtool-1.6-5
3)怎样使ethtool设置永久保存在网络设备中?
   解决方法一:
    ethtool设置可通过/etc/sysconfig/network-scripts/ifcfg-ethX文件保存,从而在设备下次启动时激活选项。
例如:ethtool -s eth0 speed 100 duplex full autoneg off
此指令将eth0设备设置为全双工自适应,速度为100Mbs。若要eth0启动时设置这些参数, 修改文件/etc/sysconfig/network-scripts/ifcfg-eth0 ,添加如下一行:
 ETHTOOL_OPTS="speed 100 duplex full autoneg off"
解决方法二:
将ethtool设置写入/etc/rc.d/rc.local之中。
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值