使用TC对LINUX服务器网卡进行带宽限制的办法

对Linux服务器网卡进行带宽限制的办法:

1、安装iproute

# yum -y install iproute

2、限制eth0网卡的带宽为500kbit:

# /sbin/tc qdisc add dev eth0 root tbf rate 500kbit latency 50ms burst 15kb

TBF Example(限制带宽为1mbit)

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, enter:

# tc qdisc add dev eth0 root tbf rate 1mbit burst 10kb latency 70ms peakrate 2mbit minburst 1540

3、解除eth0网卡的带宽限制:

# /sbin/tc qdisc del dev eth0 root

4、列出已有的策略:

# tc -s qdisc ls dev eth0

5、启动时自动加载带宽限制策略:

# vim /etc/rc.local

加入:

/sbin/tc qdisc add dev eth0 root tbf rate 500kbit latency 50ms burst 15kb

所使用的命令 sudo tc qdisc add dev em1 root tbf rate 200mbit burst 10kb latency 70ms
实际速度在47M/s左右

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注