一、安装iproute
[root@localhost ~]# yum install iproute -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * centos-sclo-rh: mirrors.bupt.edu.cn * centos-sclo-sclo: mirrors.bupt.edu.cn * epel: mirrors.bfsu.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package iproute.x86_64 0:4.11.0-14.el7 will be updated ---> Package iproute.x86_64 0:4.11.0-30.el7 will be an update --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================================================== Package Arch Version Repository Size ==================================================================================================================================== Updating: iproute x86_64 4.11.0-30.el7 base 805 k Transaction Summary ==================================================================================================================================== Upgrade 1 Package Total download size: 805 k Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. iproute-4.11.0-30.el7.x86_64.rpm | 805 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : iproute-4.11.0-30.el7.x86_64 1/2 Cleanup : iproute-4.11.0-14.el7.x86_64 2/2 Verifying : iproute-4.11.0-30.el7.x86_64 1/2 Verifying : iproute-4.11.0-14.el7.x86_64 2/2 Updated: iproute.x86_64 0:4.11.0-30.el7 Complete! [root@localhost ~]#
二、限制em1网卡的带宽为100kbit/s ,峰值为200kbit/s
[root@localhost ~]# /sbin/tc qdisc add dev em1 root tbf rate 100kbit latency 50ms burst 200kbit
使用sz进行测试
[root@localhost src]# sz v1.5-dev20.tar.gz rz Starting zmodem transfer. Press Ctrl+C to cancel. Transferring v1.5-dev20.tar.gz... 17% 199 KB 11 KB/sec 00:01:23 ETA 0 Errors
显示下载速度为11KByte/s 换算为kbit乘以8=88kbit/s差不多为100kbit/s
三、删除限速
[root@localhost ~]# /sbin/tc qdisc del dev em1 root tbf rate 100kbit latency 50ms burst 200kbit
再次测试
[root@localhost src]# sz v1.5-dev20.tar.gz rz Starting zmodem transfer. Press Ctrl+C to cancel. Transferring v1.5-dev20.tar.gz... 100% 1177 KB 1177 KB/sec 00:00:01 0 Errors [root@localhost src]#
速度变为1177*8=9416kbit
设置em1网卡带宽为3Mbit=3072kbit
[root@localhost src]# /sbin/tc qdisc add dev em1 root tbf rate 3072kbit latency 50ms burst 3072kbit
下载测试
[root@localhost src]# sz Python-3.7.0.tar.xz rz Starting zmodem transfer. Press Ctrl+C to cancel. Transferring Python-3.7.0.tar.xz... 55% 9038 KB 347 KB/sec 00:00:21 ETA 0 Errors
差不多为3000kbit