net-tool 标签文章 - 李海鑫个人博客

(2010-8-18)设置网卡的协商模式--命令工具ethtool

编辑文章 没有评论 :

ethtool: 显示网络端口设置功能;Linux下用于查询及设置网卡参数的命令。

本文HTML永久地址doc

[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已经激活;
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网卡没有激活;

(2010-8-18)查看,管理介质的网络接口的状态--命令工具mii-tool

编辑文章 没有评论 :

mii-tool介绍:linux配置网络设备协商方式的工具(这是Linux下专门设置网卡工作模式的命令)view, manipulate media-independent interface status (mii-tool 是查看,管理介质的网络接口的状态)

本文HTML永久地址doc

有时网卡需要配置协商方式 ,比如10/100/1000M的网卡半双工、全双工、自动协商的配置 。但大多数的网络设备是不用我们来修改协商,因为大多数网络设置接入的时候,都采用自动协商来解决相互通信的问题。不过自动协商也不是万能的,有时也会出 现错误,比如丢包率比较高,这时就要我们来指定网卡的协商方式 。

mii-tool 就是能指定网卡的协商方式。下面我们说一说mii-tool的用法

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 fu

(2010-8-11)网络检测工具(Iperf)

编辑文章 没有评论 :

概述

Iperf是一个网络性能测试工具。可以测试TCP和UDP带宽质量,可以测量最大TCP带宽,具有多种参数和UDP特性,可以报告带宽,延迟抖动和数据包丢失。Iperf在linux和windows平台均有二进制版本供自由使用。

Iperf was developed by NLANRDAST as a modern alternative for measuring maximum TCP and UDP bandwidth performance. Iperf allows the tuning of various parameters and UDP characteristics. Iperf reports bandwidth, delay jitter, datagram loss.

本文HTML永久地址 doc

软件下载

yum 安装:

rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
yum -y install iperf

源码安装:

tar xvf iperf-xxx.tar  #官方站:http://sourceforge.net/projects/iperf/
cd  iperf
./configure
make
make install

windows版本

下载:http://www.noc.ucf.edu/Tools/Iperf/

Iperf使用方法与参数说明

参数说明 -s 以server模式启动,eg:iperf –s 。Server端为数据的接收端。

-c host以client模式启动,host是server端地址,eg:iperf -c 222.35.11.23 。Client端为数据的发出端。

通用参数 -f [kmKM] 分别表示以Kbits, Mbits, KBytes, MBytes显示报告,默认以Mbits为单位,eg:iperf -c 222.35.11.23 -f K

-i sec 以秒为单位显示报告间隔,eg:iperf -c 222.35.11.23 -i 2

-l 缓冲区大小,默认是8KB,eg:iperf -c 222.35.11.23 -l 16

-m 显示tcp最大mtu值

-o 将报告和错误信息输出到文件eg:iperf -c 222.35.11.23 -o ciperflog.txt

-p 指定服务器端使用的端口或客户端所连接的端口eg:iperf -s -p 9999;iperf -c 222.35.11.23 -p 9999

-P 连接限制参数 例如-P 2 当两个连接建立后,服务器进程就会退出。如果这个参数设定为0,那么iperf 进程将持续监听端口,并且不限制连接数量

-u 使用udp协议

-w 指定TCP窗口大小,默认是8KB

-B 绑定一个主机地址或接口(当主机有多个地址或接口时使用该参数)

-C 兼容旧版本(当server端和client端版本不一样时使用)

-M 设定TCP数据包的最大mtu值

-N 设定TCP不延时

-V 传输ipv6数据包

server专用参数 -D 以服务方式运行ipserf,eg:iperf -s -D

-R 停止iperf服务,针对-D,eg:iperf -s -R

client端专用参数 -d 同时进行双向传输测试

-n 指定传输的字节数,eg:iperf -c 222.35.11.23 -n 100000

-r 单独进行双向传输测试

-t 测试时间,默认10秒,eg:iperf -c 222.35.11.23 -t 5

-F 指定需要传输的文件

-T 指定ttl值

应用实例

实例一

使用 iperf -s 命令将 Iperf 启动为 server 模式,在客户机上使用 iperf -c启动client模式。

服务器端:

[root@18 ~]# iperf -s
- -----------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
- -----------------------------------------------------------

客户端:

[root@vps2 ~]# iperf -c 218.64.131.18
- -----------------------------------------------------------
Client connecting to 218.64.131.18, TCP port 5001
TCP window size: 16.0 KByte (default)
- -----------------------------------------------------------
[  3] local 74.62.154.33 port 49896 connected with 218.64.131.18 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.1 sec  9.57 MBytes  7.92 Mbits/sec
[root@vps2 ~]#

上面可以测试到最大速度为7.92Mbits/sec 上面使用服务端和客户端的默认设置进行测试

实例二

服务器端设置

[root@18 ~]# iperf -s -w 300K
- -----------------------------------------------------------
Server listening on TCP port 5001
TCP window size:   216 KByte (WARNING: requested   300 KByte)
- -----------------------------------------------------------

客户端设置

[root@vps2 ~]# iperf -c 218.64.131.18 -f K -i 2 -w 300K  #设定报告间隔为2秒,服务器端和客户端的TCP窗口都开到300KB 
------------------------------------------------------------
Client connecting to 218.64.131.18, TCP port 5001
TCP window size:   256 KByte (WARNING: requested   300 KByte)
------------------------------------------------------------
 [  3] local 74.62.154.33 port 57566 connected with 218.64.131.18 port 5001
 [ ID] Interval       Transfer     Bandwidth
 [  3]  0.0- 2.0 sec    624 KBytes    312 KBytes/sec
 [  3]  2.0- 4.0 sec  1184 KBytes    592 KBytes/sec
 [  3]  4.0- 6.0 sec  1208 KBytes    604 KBytes/sec
 [  3]  6.0- 8.0 sec  1304 KBytes    652 KBytes/sec
 [  3]  8.0-10.0 sec  1344 KBytes    672 KBytes/sec
 [  3]  0.0-10.1 sec  5672 KBytes    562 KBytes/sec
 [root@vps2 ~]#


[root@vps2 ~]# iperf -c 218.64.131.18 -f K -i 2 -w 300K -n 1000000   #测试传输约1MB数据 
- -----------------------------------------------------------
Client connecting to 218.64.131.18, TCP port 5001
TCP window size:   256 KByte (WARNING: requested   300 KByte)
- -----------------------------------------------------------
[  3] local 74.62.154.33 port 58469 connected with 218.64.131.18 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 2.0 sec    824 KBytes    412 KBytes/sec
[  3]  0.0- 2.2 sec    984 KBytes    449 KBytes/sec
[root@vps2 ~]#


 [root@vps2 ~]# iperf -c 218.64.131.18 -f K -i 2 -w 300K -t 36   #测试持续36秒
- -----------------------------------------------------------
Client connecting to 218.64.131.18, TCP port 5001
TCP window size:   256 KByte (WARNING: requested   300 KByte)
- -----------------------------------------------------------
[  3] local 74.62.154.33 port 58836 connected with 218.64.131.18 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 2.0 sec    744 KBytes    372 KBytes/sec
[  3]  2.0- 4.0 sec  1280 KBytes    640 KBytes/sec
[  3]  4.0- 6.0 sec  1304 KBytes    652 KBytes/sec
[  3]  6.0- 8.0 sec  1312 KBytes    656 KBytes/sec
[  3]  8.0-10.0 sec  1296 KBytes    648 KBytes/sec
[  3] 10.0-12.0 sec  1296 KBytes    648 KBytes/sec
[  3] 12.0-14.0 sec  1288 KBytes    644 KBytes/sec
[  3] 14.0-16.0 sec  1168 KBytes    584 KBytes/sec
[  3] 16.0-18.0 sec  1304 KBytes    652 KBytes/sec
[  3] 18.0-20.0 sec  1248 KBytes    624 KBytes/sec
[  3] 20.0-22.0 sec    392 KBytes    196 KBytes/sec
[  3] 22.0-24.0 sec    712 KBytes    356 KBytes/sec
[  3] 24.0-26.0 sec    808 KBytes    404 KBytes/sec
[  3] 26.0-28.0 sec    888 KBytes    444 KBytes/sec
[  3] 28.0-30.0 sec    888 KBytes    444 KBytes/sec
[  3] 30.0-32.0 sec    896 KBytes    448 KBytes/sec
[  3] 32.0-34.0 sec    992 KBytes    496 KBytes/sec
[  3] 34.0-36.0 sec    960 KBytes    480 KBytes/sec
[  3]  0.0-36.2 sec  18784 KBytes    520 KBytes/sec
[root@vps2 ~]#   

[root@vps2 ~]# iperf -c 218.64.131.18 -f K -i 5 -w 300K -n 10400000 -d -t 60     #测试双向的传输 
- -----------------------------------------------------------
Server listening on TCP port 5001
TCP window size:   256 KByte (WARNING: requested   300 KByte)
- -----------------------------------------------------------
- -----------------------------------------------------------
Client connecting to 218.64.131.18, TCP port 5001
TCP window size:   256 KByte (WARNING: requested   300 KByte)
- -----------------------------------------------------------
[  5] local 74.62.154.33 port 36184 connected with 218.64.131.18 port 5001
[  4] local 74.62.154.33 port 5001 connected with 218.64.131.18 port 55946
[ ID] Interval       Transfer     Bandwidth
[  5]  0.0- 5.0 sec  2720 KBytes    544 KBytes/sec
[  5]  5.0-10.0 sec  3336 KBytes    667 KBytes/sec
[  5] 10.0-15.0 sec  3256 KBytes    651 KBytes/sec
[  5] 15.0-20.0 sec  3232 KBytes    646 KBytes/sec
[  5] 20.0-25.0 sec  3032 KBytes    606 KBytes/sec
[  5] 25.0-30.0 sec  1304 KBytes    261 KBytes/sec
[  5] 30.0-35.0 sec  1536 KBytes    307 KBytes/sec
[  5] 35.0-40.0 sec  1464 KBytes    293 KBytes/sec
[  5] 40.0-45.0 sec  1704 KBytes    341 KBytes/sec
[  5] 45.0-50.0 sec  1992 KBytes    398 KBytes/sec
[  5] 50.0-55.0 sec  3408 KBytes    682 KBytes/sec
[  5] 55.0-60.0 sec  3416 KBytes    683 KBytes/sec
[  5]  0.0-60.2 sec  30408 KBytes    505 KBytes/sec
[  4]  0.0- 5.0 sec  0.00 KBytes  0.00 KBytes/sec
[  4]  5.0-10.0 sec  0.00 KBytes  0.00 KBytes/sec
[  4] 10.0-15.0 sec  0.00 KBytes  0.00 KBytes/sec
[  4] 15.0-20.0 sec  0.00 KBytes  0.00 KBytes/sec
[  4] 20.0-25.0 sec  0.00 KBytes  0.00 KBytes/sec
[  4] 25.0-30.0 sec  0.00 KBytes  0.00 KBytes/sec
[  4] 30.0-35.0 sec  0.00 KBytes  0.00 KBytes/sec
[  4] 35.0-40.0 sec  0.00 KBytes  0.00 KBytes/sec
[  4] 40.0-45.0 sec  0.00 KBytes  0.00 KBytes/sec
[  4] 45.0-50.0 sec  0.00 KBytes  0.00 KBytes/sec
[  4] 50.0-55.0 sec  0.00 KBytes  0.00 KBytes/sec
[  4]  0.0-60.0 sec  34952 KBytes    583 KBytes/sec
[root@vps2 ~]#


[root@vps2 ~]# iperf -c 218.64.131.18 -f K -i 2 -w 300K -u -t 10    #UDP测试
- -----------------------------------------------------------
Client connecting to 218.64.131.18, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size:   256 KByte (WARNING: requested   300 KByte)
- -----------------------------------------------------------
[  3] local 74.62.154.33 port 48551 connected with 218.64.131.18 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 2.0 sec  29360375 KBytes  14680187 KBytes/sec
[  3]  2.0- 4.0 sec  8388861 KBytes  4194430 KBytes/sec
[  3]  4.0- 6.0 sec  8388861 KBytes  4194430 KBytes/sec
[  3]  6.0- 8.0 sec  8388862 KBytes  4194431 KBytes/sec
[  3]  8.0-10.0 sec  8388861 KBytes  4194430 KBytes/sec
[  3]  0.0-10.0 sec  62915820 KBytes  6281749 KBytes/sec
[  3] Sent 893 datagrams
read failed: Connection refused
[  3] WARNING: did not receive ack of last datagram after 2 tries.
[root@vps2 ~]#

实例三:windows 测试实例

服务器端设置:

C:\>iperf.exe -s
- -----------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 8.00 KByte (default)
- -----------------------------------------------------------
[1864] local 218.64.131.18 port 5001 connected with 59.42.207.131 port 18875
[ ID] Interval       Transfer     Bandwidth
[1864]  0.0-15.4 sec   800 KBytes   426 Kbits/sec

客户端连接

C:\>iperf.exe -c 218.64.131.18 -i 5 -t 15
- -----------------------------------------------------------
Client connecting to 218.64.131.18, TCP port 5001
TCP window size: 8.00 KByte (default)
- -----------------------------------------------------------
[1912] local 192.168.3.12 port 1901 connected with 218.64.131.18 port 5001
[ ID] Interval       Transfer     Bandwidth
[1912]  0.0- 5.0 sec   264 KBytes   433 Kbits/sec
[1912]  5.0-10.0 sec   264 KBytes   433 Kbits/sec
[1912] 10.0-15.0 sec   264 KBytes   433 Kbits/sec
[1912]  0.0-15.4 sec   800 KBytes   425 Kbits/sec

C:\>

从上面可以看到本机传输到服务器的最大速度为425 Kbits/sec,我本机使用的ADSL宽带,所以速度慢一点。