- #!/bin/sh
- # The Ultimate Setup For Your Internet Connection At Home
- # Set the following values to somewhat less than your actual download
- # and uplink speed. In kilobits
- # adsl uplink capacity in kbit
- UPLINK=45
- # which device are we throttling
- DEV=eth1
- # clean existing down- and uplink qdiscs, hide errors
- tc qdisc del dev $DEV root &>/dev/null
- tc qdisc del dev $DEV ingress &>/dev/null
- # clean existing iptables fwmark
- iptables -t mangle -F
- iptables -t mangle -X
- # install root HTB
- tc qdisc add dev $DEV root handle 1: htb
- tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit
- tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit burst 6k prio 1
- tc class add dev $DEV parent 1:1 classid 1:20 htb rate $[9*$UPLINK/10]kbit burst 6k prio 2
- tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
- tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
- tc filter add dev $DEV parent 1:0 prio 0 protocol ip handle 10 fw flowid 1:10
- tc filter add dev $DEV parent 1:0 prio 0 protocol ip handle 20 fw flowid 1:20
- iptables -t mangle -N MYSHAPER-OUT
- iptables -t mangle -A POSTROUTING -o $DEV -j MYSHAPER-OUT
- iptables -t mangle -A MYSHAPER-OUT -s 192.168.0.0/24 -j RETURN
- # tcp ack gets high-prio
- #iptables -t mangle -A MYSHAPER-OUT -p tcp -m length --length :68 -j MARK --set-mark 10
- iptables -t mangle -A MYSHAPER-OUT -p tcp --tcp-flags ALL ACK -m state --state ESTABLISHED -m length --length 0:100 -j MARK --set-mark 10
- # so does icmp and udp
- iptables -t mangle -A MYSHAPER-OUT -p icmp -j MARK --set-mark 10
- iptables -t mangle -A MYSHAPER-OUT -p udp -j MARK --set-mark 10
- # defaults, get lower priority
- iptables -t mangle -A MYSHAPER-OUT -m mark --mark 0 -j MARK --set-mark 20
- #iptables -t mangle -A MYSHAPER-OUT -p tcp -m length --length :64 -j CLASSIFY --set-class 1:10
- #iptables -t mangle -A MYSHAPER-OUT -p tcp --tcp-flags ALL ACK -m state --state ESTABLISHED -m length --length :100 -j CLASSIFY --set-class 1:10
- #iptables -t mangle -A MYSHAPER-OUT -p icmp -j CLASSIFY --set-class 1:10
- #iptables -t mangle -A MYSHAPER-OUT -p udp -j CLASSIFY --set-class 1:10
- #iptables -t mangle -A MYSHAPER-OUT -m mark --mark 0 -j CLASSIFY --set-class 1:20
- # http://www.knowplace.org/pages/howtos/traffic_shaping_with_linux/examples.php
- # http://trekweb.com/~jasonb/articles/traffic_shaping/scenarios.html
- # http://www.shorewall.net/traffic_shaping.htm
- # http://www.docum.org/docum.org/faq/cache/49.html
