Archive for January 17th, 2013

Shaping in Slackware

Thursday, January 17th, 2013

An ‘iproute2’ package (description) must be installed. Let’s imagine that we use a default kernel in which ‘everything is included but the kitchen sink’. :)

FIRST. Create /etc/rc.d/rc.shaper with the following code:


#!/bin/bash
shaper_start() {
tc qdisc add dev eth1 root handle 1:0 htb default 254

tc class add dev eth1 parent 1:0 classid 1:1 htb rate 0.5mbit
tc class add dev eth1 parent 1:0 classid 1:2 htb rate 3.3mbit
tc class add dev eth1 parent 1:0 classid 1:254 htb rate 256kbit

tc filter add dev eth1 protocol ip parent 1:0 prio 1 u32 match ip dst 192.168.0.2 flowid 1:1
tc filter add dev eth1 protocol ip parent 1:0 prio 1 u32 match ip dst 192.168.0.3 flowid 1:2
}

shaper_stop() {
tc qdisc del dev eth1 root
}
shaper_restart() {
shaper_stop
sleep 1
shaper_start
}

case "$1" in
'start')
shaper_start
;;
'stop')
shaper_stop
;;
'restart')
shaper_restart
;;
*)
echo "usage $0 start|stop|restart"

SECOND. Make it executable: chmod +x /etc/rc.d/rc.shaper

THIRD. Add to /etc/rc.d/rc.inet2 these lines:


if [ -x /etc/rc.d/rc.shaper ]; then
/etc/rc.d/rc.shaper start
fi

Now type /etc/rc.d/rc.shaper start. After that your client with 192.168.0.2 IP address will have a 0.5 mbit/s bandwidth and 192.168.0.3 one will have 3.3 mbit/s. Any other IPs will have 256 kbit/s only, as it is set in the default shaping rule.