[转]Linux 下流量控制等 (Netemulator,tc)

netem provides Network Emulation functionality for testing protocols by emulating the properties of wide area networks. The current version emulates variable delay, loss, duplication and re-ordering.

If you run a current 2.6 distribution, (Fedora, OpenSuse, Gentoo, Debian, Mandriva, Ubuntu), then netem is already enabled in the kernel and a current version of iproute2 is included. The netem kernel component is enabled under:

Networking -->
Networking Options -->
QoS and/or fair queuing -->
Network emulator

端口延时命令

# tc qdisc add dev eth0 root netem delay 100ms

表示对端口廷时100ms

# tc qdisc del dev eth0 root netem delya 100ms

表示对端口廷时命令删除

# tc qdisc change dev eth0 root netem delay 100ms 10ms

表示对改变端口廷时命100ms ± 10ms 延时范围(90110

# tc qdisc change dev eth0 root netem delay 100ms 10ms 25%

表示廷时范围100ms ± 10ms * 25%


端口丢包命令:

# tc qdisc change dev eth0 root netem loss 0.1%

丢包率为01%

# tc qdisc change dev eth0 root netem loss 0.3% 25%

丢包率为范围(03% 25%


[edit]

[ed数据包副本命令

# tc qdisc change dev eth0 root netem duplicate 1%

数据包副本率 1%

[edit] [edi数据包分发命令

# tc qdisc change dev eth0 root netem gap 5 delay 10ms

数据包重发每格5的整数倍的包将不被延时。其它的将延时10ms


[edit] 速率控制命令:两条命令共同完成

# tc qdisc add dev eth0 root handle 1:0 netem delay 100ms

# tc qdisc add dev eth0 parent 1:1 handle 10: tbf rate 256kbit buffer 1600 limit 3000

# tc -s qdisc ls dev eth0 ----查看规则信息。

# tc qdisc show

更多帮助

# tc help , tc qdisc help

以上是建立速率控制命令规则。红色部分为限制包数量可去掉


清除规则命令:

tc qdisc del dev eth0 root

完毕后可以先试试bridge的基本命令:(这是可以把此主机看到两个端口的HUB )
brctl addbr mybridge
(创建bridge mybridge,然后用ifconfig查看会发现多了一个mybridge端口)
brctl addif mybridge eth0  
brctl addif mybridge eth1
(把eth0eth1包含到mybridge中)

然后需要对各端口做以下动作
ifconfig eth0 0.0.0.0 promisc  
ifconfig eth1 0.0.0.0 promisc
(打开混杂模式)
ifconfig mybridge up(
启动网桥)

posted on 2009-09-15 18:58  灰原  阅读(970)  评论(0编辑  收藏  举报

导航