linux下简单限制网卡速度
Linux下限制网卡的带宽,可用来模拟服务器带宽耗尽,从而测试服务器在此时的访问效果。
1、安装iproute
yum -y install iproute
2、限制eth0网卡的带宽为50kbit:
/sbin/tc qdisc add dev eth0 root tbf rate 50kbit latency 50ms burst 1000
3、限制带宽为50kbit后,在百兆局域网中wget下载一个大文件:
[root@localhost ~]# wget http://192.168.1.7/test.zip
--19:40:27-- http://192.168.1.7/test.zip
Connecting to 192.168.1.7:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 23862312 (23M) [application/zip]
Saving to: `test.zip'
37% [=======> ] 8,994,816 457K/s eta 27s
下载速度为457K/s,限制效果达到。
4、解除eth0网卡的带宽限制:
/sbin/tc qdisc del dev eth0 root tbf
5、对比:未作带宽限制情况下,在百兆局域网中wget下载一个大文件:
[root@localhost ~]# wget http://192.168.1.7/test.zip
--19:44:33-- http://192.168.1.7/test.zip
Connecting to 192.168.1.7:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 23862312 (23M) [application/zip]
Saving to: `test.zip'
100%[==========>] 23,862,312 6.14M/s in 3.7s
19:44:36 (6.16 MB/s) - `test.zip' saved [23862312/23862312]
下载速度为6.16MB/s。
linux下针对源地址可以做流量的限速:
# iptables -A INPUT -p tcp -s 192.168.80.12 -m limit --limit 30/sec --limit-burst 3 -j ACCEPT
# iptables -A INPUT -p tcp -s 192.168.80.12 -j DROP
# iptables -A OUTPUT -p tcp -d 192.168.80.12 -m limit --limit 30/sec --limit-burst 3 -j ACCEPT
# iptables -A OUTPUT -p tcp -d 192.168.80.12 -m limit --limit 30/sec --limit-burst 3 -j ACCEPT
#iptables -A OUTPUT -p tcp -d 192.168.80.12 -j DROP
iptables -A INPUT -p tcp -s 192.168.80.15 -m limit --limit 5/sec --limit-burst 3 -j ACCEPT
iptables -A INPUT -p tcp -s 192.168.80.15 -j DROP
iptables -A OUTPUT -p tcp -s 192.168.80.15 -m limit --limit 5/sec --limit-burst 3 -j ACCEPT
iptables -A OUTPUT -p tcp -s 192.168.80.15 -j DROP
Linux下限制网卡的带宽
2010年9月6日
10:40
Q: Iptables限制包的流速
A: 由-m limit --limit <[!]limitnum> --limit-burst <burstnum>
--limit: 速率限制/sec /minute /hour
--limit-burst: 最大的连接数。这个是用来限制最大可用数的。因为:
1. 如果当前包速超过limit限定的值的时,超速部分将直接跳过当前规则,进
入下一条规则的匹配。
2. 如果当前没有包来,则limit会将该单位时间内的剩余量累计入下个单位时
间,但最大值不超过--limit-burst指定的值。
实例:从10.226.52.1上下载一个大文件,比较限速前与限速后的下载速度。。
限制速度前 (10M/s):过程如下所示
-bash-3.1#wget http://10.226.52.1/5GB.zip
--16:38:38-- http://10.226.52.1/5GB.zip
Connecting to 10.226.52.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5362862509 (5.0G) [application/octet-stream]
Saving to: `5GB.zip'
2% [ ] 113,341,300 10.0M/s eta 9m 43s
限制速度后:
-bash-3.1# iptables -A INPUT -p tcp -s 10.226.52.1 -m limit --limit 30/sec --limit-burst 3 -j ACCEPT
-bash-3.1# iptables -A INPUT -p tcp -s 10.226.52.1 -j DROP (加这条的原因是INPUT链上的默认规则是ACCEPT)
-bash-3.1# iptables -A OUTPUT -p tcp -d 10.226.52.1 -m limit --limit 30/sec --limit-burst 3 -j ACCEPT
-bash-3.1# iptables -A OUTPUT -p tcp -d 10.226.52.1 -j DROP
-bash-3.1# wget http://10.226.52.1/5GB.zip
--10:08:32-- http://10.226.52.1/5GB.zip
Connecting to 10.226.52.1:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5362862509 (5.0G) [application/octet-stream]
Saving to: `5GB.zip'
0% [ ] 461,912 14.1K/s eta 5d 19h
将上面的30/3改成5/5网速就限制在了7K/s左右
第三种:
#ethtool -s eth0 speed 10 将千兆网卡改成10兆的网卡
linux下简单限制网卡速度的更多相关文章
- Linux下简单的socket通信实例
Linux下简单的socket通信实例 If you spend too much time thinking about a thing, you’ll never get it done. —Br ...
- Linux 下 简单客户端服务器通讯模型(TCP)
原文:Linux 下 简单客户端服务器通讯模型(TCP) 服务器端:server.c #include<stdio.h> #include<stdlib.h> #include ...
- Linux下简单的取点阵字模程序
源:Linux下简单的取点阵字模程序 Linux操作系统下进行简单的图形开发,经常会用到取字模的软件,但是Linux并没有像Windows下的小工具可用,我们也并不希望为了取字模而频繁地切换操作系统. ...
- linux下简单的备份的脚本 2 【转】
转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=26807463&id=4577034 之前写过linux下简单的 ...
- 一个linux下简单的纯C++实现Http请求类(GET,POST,上传,下载)
目录 一个linux下简单的纯C++实现Http请求类(GET,POST,上传,下载) Http协议简述 HttpRequest类设计 请求部分 接收部分 关于上传和下载 Cpp实现 关于源码中的Lo ...
- Linux下简单粗暴使用rsync实现文件同步备份【转】
这篇来说说如何安全的备份,还有一点不同的是上一篇是备份服务器拉取数据,这里要讲的是主服务器如何推送数据实现备份. 一.备份服务器配置rsync文件 vim /etc/rsyncd.conf #工作中指 ...
- linux下简单好用的端口映射转发工具rinetd 转
linux下简单好用的工具rinetd,实现端口映射/转发/重定向 官网地址http://www.boutell.com/rinetd 软件下载 wget http://www.boutell.com ...
- linux下简单好用的端口映射转发工具rinetd
linux下简单好用的工具rinetd,实现端口映射/转发/重定向官网地址http://www.boutell.com/rinetd 软件下载wget http://www.boutell.com/r ...
- linux下开发板网络速度测试记录
由于做的项目对于网络和USB的读写速度有很高的要求,因此新拿回来的板子要测试网络和usb的最佳传输速度.要考虑不少因素,先把我能想到的记录下来. 测试的环境是开发板和ubuntu虚拟机 ...
随机推荐
- ssh-copy-id
建立无密码登录是经现root成功普通用户失败, chmod 0600 authorized_keys setenforce 0 ssh-copy-id server2 ssh-add ~/.ss ...
- windows cmd 命令大全
原文: http://www.cnblogs.com/greatverve/archive/2011/12/09/windows-cmd.html 命令简介 cmd是command的缩写.即命令行 . ...
- Not a million dollars ——a certain kind of ingenuity, discipline, and proactivity that most people seem to lack
原文:http://ryanwaggoner.com/2010/12/you-dont-really-want-a-million-dollars/a certain kind of ingenuit ...
- PAT1011
With the 2010 FIFA World Cup running, 随着2010世界杯的举行 football fans the world over were becoming increa ...
- mysql触发器的使用
环境情况: 表1:residential_building,住宅楼表:id,community(所属社区),countFloor(楼层数),countUnit(单元数),countHomesInUni ...
- PAT (Advanced Level) 1002. A+B for Polynomials (25)
为0的不要输出. #include<iostream> #include<cstring> #include<cmath> #include<algorith ...
- spark 文件系统Alluxio(之前名为Tachyon)
http://www.alluxio.org/documentation/v1.0.0/cn/ http://www.winseliu.com/blog/2016/04/15/alluxio-quic ...
- Sequence Classification
Natural Language Processing with Python Charpter 6.1 import nltk from nltk.corpus import brown def p ...
- (简单) POJ 3074 Sudoku, DLX+精确覆盖。
Description In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller 3 × 3 subgr ...
- OC语言的特性(二)-Block
本篇文章的主要内容 了解何谓block. 了解block的使用方法. Block 是iOS在4.0版本之后新增的程序语法. 在iOS SDK 4.0之后,Block几乎出现在所有新版的API之中,换句 ...