首页 » 操作系统 » Linux » Linux使用wondershaper限制网络带宽

Linux使用wondershaper限制网络带宽

 

安装wondershaper

安装git命令,再进入/根目录,克隆wondershaper脚本

[root@localhost ~]# yum install git -y
[root@localhost ~]# cd /
[root@localhost /]# git clone https://github.com/magnific0/wondershaper.git

wondershaper帮助

USAGE: ./wondershaper [-hcs] [-a ] [-d ] [-u ]
Limit the bandwidth of an adapter
OPTIONS:
   -h           Show this message
   -a  Set the adpter
   -d     Set maximum download rate (in Kbps) and/or
   -u     Set maximum upload rate (in Kbps)
   -p           Use presets in /etc/conf.d/wondershaper.conf
   -c           Clear the limits from adapter
   -s           Show the current status of adapter
   -v           Show the current version
MODES:
   wondershaper -a  -d  -u 
   wondershaper -c -a 
   wondershaper -s -a 
EXAMPLES:
   wondershaper -a eth0 -d 1024 -u 512
   wondershaper -a eth0 -u 512

参数说明:

-a :指定要限制的网卡名称或者接口名称
-d :最大下载速率,单位:Kbps 。Kbps 即 Kb/s,p 是 peer 的意思。1KB/s=8Kb/s。1MB/s=1024KB/s。
-u :最大上传速率,单位:Kbps 。
-p :使用 /etc/conf.d/wondershaper.conf 的配置
-c :清空所有规则,不再做任何限制
-s :显示接口的当前状态

开启限速
给网卡eth0开启限速,设置下载和上传速度分别为8192kbps,即8M带宽

[root@localhost /]# sh /wondershaper/wondershaper -a eth0 -d 8192 -u 8192
Action 4 device ifb0 ifindex 3

注:这里的限速规则,重启服务器后就会失效,可以把命令写进/etc/rc.local,开机自动执行限速命令。

取消限速

[root@localhost /]# sh /wondershaper/wondershaper -a eth0 -c

查看限速状态

[root@localhost ~]# sh /wondershaper/wondershaper -a eth0 -s
qdisc htb 1: root refcnt 2 r2q 10 default 20 direct_packets_stat 0
 Sent 703202 bytes 1107 pkt (dropped 0, overlimits 783 requeues 0) 
 rate 0bit 0pps backlog 0b 0p requeues 0 
qdisc sfq 10: parent 1:10 limit 127p quantum 6000b perturb 10sec 
 Sent 75412 bytes 608 pkt (dropped 0, overlimits 0 requeues 0) 
 rate 0bit 0pps backlog 0b 0p requeues 0 
qdisc sfq 20: parent 1:20 limit 127p quantum 6000b perturb 10sec 
 Sent 624856 bytes 351 pkt (dropped 0, overlimits 0 requeues 0) 
 rate 0bit 0pps backlog 0b 0p requeues 0 
qdisc sfq 30: parent 1:30 limit 127p quantum 6000b perturb 10sec 
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
 rate 0bit 0pps backlog 0b 0p requeues 0 
qdisc ingress ffff: parent ffff:fff1 ---------------- 
 Sent 731922 bytes 881 pkt (dropped 0, overlimits 0 requeues 0) 
 rate 0bit 0pps backlog 0b 0p requeues 0 
class htb 1:1 root rate 8192Kbit ceil 8192Kbit burst 1598b cburst 1598b 
 Sent 704184 bytes 1108 pkt (dropped 0, overlimits 0 requeues 0) 
 rate 196712bit 38pps backlog 0b 0p requeues 0 
 lended: 159 borrowed: 0 giants: 0
 tokens: 9406 ctokens: 9406

class htb 1:10 parent 1:1 leaf 10: prio 1 rate 1638Kbit ceil 7782Kbit burst 1599b cburst 1598b 
 Sent 76394 bytes 609 pkt (dropped 0, overlimits 0 requeues 0) 
 rate 21800bit 21pps backlog 0b 0p requeues 0 
 lended: 609 borrowed: 0 giants: 0
 tokens: 47015 ctokens: 9891

class htb 1:20 parent 1:1 leaf 20: prio 2 rate 3276Kbit ceil 7782Kbit burst 1599b cburst 1598b 
 Sent 627790 bytes 499 pkt (dropped 0, overlimits 0 requeues 0) 
 rate 174912bit 18pps backlog 0b 0p requeues 0 
 lended: 193 borrowed: 159 giants: 0
 tokens: -47090 ctokens: -16667

class htb 1:30 parent 1:1 leaf 30: prio 3 rate 1638Kbit ceil 7372Kbit burst 1599b cburst 1599b 
 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) 
 rate 0bit 0pps backlog 0b 0p requeues 0 
 lended: 0 borrowed: 0 giants: 0
 tokens: 122093 ctokens: 27125

原文链接:Linux使用wondershaper限制网络带宽,转载请注明来源!

0