Linux服务器使⽤tc命令对⽹卡流量上下⾏限速
⼀、安装wondershaper软件
由于CentOS7第三⽅库内才有这个软件,先安装第三⽅库
将上⾏带宽限制为1M,下⾏带宽限制为10M
清除原有规则(两个参数可以是任何字符)
查看已有规则(查看eth0的规则)
参数详解
⼀般为3个参数,第⼀个参数为⽹卡名,第⼆个上⾏速度(出)限制,第三个参数为下⾏速度(⼊)限制。
⼆、不愿意下载软件或者没有下载条件的可以使⽤下⾯这种步骤,代码是wondershaper软件内的
1.创建⼀个⽂件,并添加可执⾏权限
2.复制代码下⽅代码到刚刚创建的⽂件内,并放⼊/usr/bin⽬录下
yuminstallepel-relea-y
yuminstallwondershaper-y
wondershapereth
wondershapercleanclean
wondershapereth0
touchwondershaper&&chmod+xwondershaper
viwondershaper
mvwondershaper/usr/sbin
#!/bin/bash
functionshow_help{
echo"Usage:$0[device]clean|[uploadspeedinKb/s][downloadspeedinKb/s]"
echo"Example:$0eth020500"
exit
}
if[$#-eq0];then
show_help;
fi
if[$#-eq1];then
tc-sqdisclsdev$1
tc-sclasslsdev$1
exit
fi
if[$#-eq2];then
tcqdiscdeldev$2root2>/dev/null>/dev/null
tcqdiscdeldev$2ingress2>/dev/null>/dev/null
echoWondershaperqueueshavebeencleared.
exit
fi
fi
if[$#-ne3];then
show_help;
fi
DOWNLINK=$3
UPLINK=$2
DEV=$1
#lowprioritysourcenetmasks
NOPRIOHOSTSRC=
#lowprioritydestinationnetmasks
NOPRIOHOSTDST=
#lowprioritysourceports
NOPRIOPORTSRC=
#lowprioritydestinationports
NOPRIOPORTDST=
#cleanexistingdown-anduplinkqdiscs,hideerrors
tcqdiscdeldev$DEVroot2>/dev/null>/dev/null
tcqdiscdeldev$DEVingress2>/dev/null>/dev/null
if["$1"="stop"]
then
exit
fi
tcqdiscadddev$DEVroothandle1:cbqavpkt1000bandwidth10mbit
tcclassadddev$DEVparent1:classid1:1cbqrate${UPLINK}kbit
allot1500prio5boundedisolated
tcclassadddev$DEVparent1:1classid1:10cbqrate${UPLINK}kbit
allot1600prio1avpkt1000
tcclassadddev$DEVparent1:1classid1:20cbqrate$[9*$UPLINK/10]kbit
allot1600prio2avpkt1000
tcclassadddev$DEVparent1:1classid1:30cbqrate$[8*$UPLINK/10]kbit
allot1600prio2avpkt1000
tcqdiscadddev$DEVparent1:10handle10:sfqperturb10
tcqdiscadddev$DEVparent1:20handle20:sfqperturb10
tcqdiscadddev$DEVparent1:30handle30:sfqperturb10
tcfilteradddev$DEVparent1:0protocolipprio10u32
matchiptos0x100xffflowid1:10
tcfilteradddev$DEVparent1:0protocolipprio11u32
matchipprotocol10xffflowid1:10
tcfilteradddev$DEVparent1:0protocolipprio10u32
matchipprotocol170xff
matchipsport46660xffff
flowid1:30
tcfilteradddev$DEVparent1:protocolipprio12u32
matchipprotocol60xff
matchu80x050x0fat0
matchu160x00000xffc0at2
flowid1:10
forain$NOPRIOPORTDST
do
tcfilteradddev$DEVparent1:protocolipprio14u32
matchipdport$a0xffffflowid1:30
done
forain$NOPRIOPORTSRC
do
tcfilteradddev$DEVparent1:protocolipprio15u32
matchipsport$a0xffffflowid1:30
done
forain$NOPRIOHOSTSRC
do
tcfilteradddev$DEVparent1:protocolipprio16u32
matchipsrc$aflowid1:30
done
forain$NOPRIOHOSTDST
do
tcfilteradddev$DEVparent1:protocolipprio17u32
matchipdst$aflowid1:30
done
tcfilteradddev$DEVparent1:protocolipprio18u32
matchipdst0.0.0.0/0flowid1:20
tcqdiscadddev$DEVhandleffff:ingress
tcfilteradddev$DEVparentffff:protocolipprio50u32matchipsrc
0.0.0.0/0policerate${DOWNLINK}kbitburst10kdropflowid:1
本文发布于:2023-03-05 17:58:14,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/1678010294148435.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:上行速度.doc
本文 PDF 下载地址:上行速度.pdf
留言与评论(共有 0 条评论) |