Skip to content

Instantly share code, notes, and snippets.

@shahifaqeer
Created February 5, 2014 23:14
Show Gist options
  • Save shahifaqeer/8835346 to your computer and use it in GitHub Desktop.
Save shahifaqeer/8835346 to your computer and use it in GitHub Desktop.
#opkg install ip tc kmod-sched
INTERFACE=$1
RATELIMIT=$2
RATECEIL=$3
#insmod sch_netem
#insmod sch_tbf
#insmod sch_htb
#insmod sch_prio
#insmod cls_u32
#insmod sch_sfq
#insmod cls_fw
tc qdisc del dev $INTERFACE root
# This line sets a HTB qdisc on the root of eth0, and it specifies that the class 1:30 is used by default. It sets the name of the root as 1:, for future references.
tc qdisc add dev $INTERFACE root handle 1: htb default 30
# This creates a class called 1:1, which is direct descendant of root (the parent is 1:), this class gets assigned also an HTB qdisc, and then it sets a max rate of 6mbits, with a burst of 15k
tc class add dev $INTERFACE parent 1: classid 1:1 htb rate 800mbit burst 15k
# The previous class has this branches:
# Class 1:10, which has a rate of 800mbit
tc class add dev $INTERFACE parent 1:1 classid 1:10 htb rate 800mbit burst 15k
# Class 1:30, which has a rate of 512kbit. This one is the default class.
tc class add dev $INTERFACE parent 1:1 classid 1:30 htb rate $RATELIMIT ceil $RATECEIL burst 10k
# Martin Devera, author of HTB, then recommends SFQ for beneath these classes:
tc qdisc add dev $INTERFACE parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev $INTERFACE parent 1:30 handle 30: sfq perturb 10
# This command adds a filter to the qdisc 1: of dev eth0, set the priority of the filter to 1, matches packages with a destination port 22, and make the class 1:10 process the packages that match
tc filter add dev $INTERFACE protocol ip parent 1: prio 1 u32 match ip dport 22 0xffff flowid 1:10
tc filter add dev $INTERFACE protocol ip parent 1: prio 1 u32 match ip sport 22 0xffff flowid 1:10
tc filter add dev $INTERFACE protocol ip parent 1: prio 1 u32 match ip dport 5222 0xffff flowid 1:10
tc filter add dev $INTERFACE protocol ip parent 1: prio 1 u32 match ip sport 5222 0xffff flowid 1:10
tc -s qdisc ls dev $INTERFACE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment