对 Linux 服务器网卡进行带宽限制的办法:
1、安装 iproute
yum -y install iproute
2、限制网卡带宽
A. 限制 eth0 网卡的带宽为 500kbit:
tc qdisc add dev eth0 root tbf rate 500kbit latency 50ms burst 15kb
B. 限制 eth0 网卡的带宽为 1mbit:
tc qdisc add dev eth0 root tbf rate 1mbit burst 10kb latency 70ms peakrate 2mbit minburst 1540
上述命令的介绍如下:
To attach a TBF with a sustained maximum rate of 1mbit/s, a peakrate of 2.0mbit/s, a 10kilobyte buffer, with a pre-bucket queue size limit calculated so the TBF causes at most 70ms of latency, with perfect peakrate behavior.
3、解除 eth0 网卡的带宽限制
tc qdisc del dev eth0 root
4、列出 eth0 网卡已有的策略
tc -s qdisc ls dev eth0
5、启动时自动加载带宽限制策略
在 /etc/rc.local
中加入相应的策略,如:
tc qdisc add dev eth0 root tbf rate 500kbit latency 50ms burst 15kb