IP限速

#!/bin/sh

rmmod ifb

insmod ifb numifbs=4

insmod sch_fq_codel

insmod sch_hfsc

insmod sch_ingress

insmod cls_u32

insmod em_u32

insmod act_connmark

insmod act_mirred

insmod cls_fw

############################# 上行 ##############################
ifconfig ifb2 up

tc qdisc add dev ifb2 root handle 1:0 hfsc default 10

#最大6M
tc class add dev ifb2 parent 1:0 classid 1:1 hfsc sc rate 1000kbit ul rate 6000kbit 

#最大6M
tc class add dev ifb2 parent 1:1 classid 1:10 hfsc sc rate 500kbit ul rate 6000kbit 

#单个IP上行限速、保证速率1M 最大1.2M#
tc class add dev ifb2 parent 1:1 classid 1:20 hfsc sc rate 1000kbit ul rate 1200kbit
tc class add dev ifb2 parent 1:1 classid 1:30 hfsc sc rate 1000kbit ul rate 1200kbit
tc class add dev ifb2 parent 1:1 classid 1:40 hfsc sc rate 1000kbit ul rate 1200kbit
tc class add dev ifb2 parent 1:1 classid 1:50 hfsc sc rate 1000kbit ul rate 1200kbit
tc class add dev ifb2 parent 1:1 classid 1:60 hfsc sc rate 1000kbit ul rate 1200kbit
tc class add dev ifb2 parent 1:1 classid 1:70 hfsc sc rate 1000kbit ul rate 1200kbit

#源IP:192.168.10.2-192.168.10.7过滤,192.168.10.2对应十六进制C0A80A02
tc filter add dev ifb2 parent 1:0 protocol all u32 match u32 0xC0A80A02 0xffffffff at 12 flowid 1:20
tc filter add dev ifb2 parent 1:0 protocol all u32 match u32 0xC0A80A03 0xffffffff at 12 flowid 1:30
tc filter add dev ifb2 parent 1:0 protocol all u32 match u32 0xC0A80A04 0xffffffff at 12 flowid 1:40
tc filter add dev ifb2 parent 1:0 protocol all u32 match u32 0xC0A80A05 0xffffffff at 12 flowid 1:50
tc filter add dev ifb2 parent 1:0 protocol all u32 match u32 0xC0A80A06 0xffffffff at 12 flowid 1:60
tc filter add dev ifb2 parent 1:0 protocol all u32 match u32 0xC0A80A07 0xffffffff at 12 flowid 1:70
############################# 下行 ##############################
ifconfig ifb3 up

tc qdisc add dev ifb3 root handle 1: hfsc default 10
#最大6M
tc class add dev ifb3 parent 1:0 classid 1:1 hfsc sc rate 1000kbit ul rate 6000kbit 
#最大6M
tc class add dev ifb3 parent 1:1 classid 1:10 hfsc sc rate 500kbit ul rate 6000kbit

#单个IP下行限速、保证速率1M 最大1.2M#
tc class add dev ifb3 parent 1:1 classid 1:20 hfsc sc rate 1000kbit ul rate 1200kbit
tc class add dev ifb3 parent 1:1 classid 1:30 hfsc sc rate 1000kbit ul rate 1200kbit
tc class add dev ifb3 parent 1:1 classid 1:40 hfsc sc rate 1000kbit ul rate 1200kbit
tc class add dev ifb3 parent 1:1 classid 1:50 hfsc sc rate 1000kbit ul rate 1200kbit
tc class add dev ifb3 parent 1:1 classid 1:60 hfsc sc rate 1000kbit ul rate 1200kbit
tc class add dev ifb3 parent 1:1 classid 1:70 hfsc sc rate 1000kbit ul rate 1200kbit

#目的IP:192.168.10.2-192.168.10.7过滤,192.168.10.2对应十六进制C0A80A02
tc filter add dev ifb3 parent 1:0 protocol all u32 match u32 0xC0A80A02 0xffffffff at 16 flowid 1:20
tc filter add dev ifb3 parent 1:0 protocol all u32 match u32 0xC0A80A03 0xffffffff at 16 flowid 1:30                   
tc filter add dev ifb3 parent 1:0 protocol all u32 match u32 0xC0A80A04 0xffffffff at 16 flowid 1:40                     
tc filter add dev ifb3 parent 1:0 protocol all u32 match u32 0xC0A80A05 0xffffffff at 16 flowid 1:50
tc filter add dev ifb3 parent 1:0 protocol all u32 match u32 0xC0A80A06 0xffffffff at 16 flowid 1:60
tc filter add dev ifb3 parent 1:0 protocol all u32 match u32 0xC0A80A07 0xffffffff at 16 flowid 1:70
############# br-mgr_lan #########################
tc qdisc add dev br-mgr_lan handle ffff: ingress

tc filter add dev br-mgr_lan parent ffff: protocol all u32 match u32 0 0  flowid 10:10 action mirred egress redirect dev ifb2

tc qdisc add dev br-mgr_lan root handle 1: fq_codel

tc filter add dev br-mgr_lan parent 1: protocol all u32 match u32 0 0 flowid 10:10 action mirred egress redirect dev ifb3

你可能感兴趣的:(IP限速)