Share Pastebin
Guest
Public paste!

shape single int LTSP

By: a guest | May 6th, 2008 | Syntax: None | Size: 2.44 KB | Hits: 434 | Expires: Never
Copy text to clipboard
  1. #!/bin/sh
  2. # The Ultimate Setup For Your Internet Connection At Home
  3. # Set the following values to somewhat less than your actual download
  4. # and uplink speed. In kilobits
  5.  
  6. # adsl uplink capacity in kbit
  7. UPLINK=45
  8.  
  9. # which device are we throttling
  10. DEV=eth1
  11.  
  12. # clean existing down- and uplink qdiscs, hide errors
  13. tc qdisc del dev $DEV root    &>/dev/null
  14. tc qdisc del dev $DEV ingress &>/dev/null
  15.  
  16. # clean existing iptables fwmark
  17. iptables -t mangle -F
  18. iptables -t mangle -X
  19.  
  20. # install root HTB
  21. tc qdisc add dev $DEV root handle 1: htb
  22.  
  23. tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit
  24. tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit burst 6k prio 1
  25. tc class add dev $DEV parent 1:1 classid 1:20 htb rate $[9*$UPLINK/10]kbit burst 6k prio 2
  26.  
  27. tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
  28. tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
  29.  
  30. tc filter add dev $DEV parent 1:0 prio 0 protocol ip handle 10 fw flowid 1:10
  31. tc filter add dev $DEV parent 1:0 prio 0 protocol ip handle 20 fw flowid 1:20
  32.  
  33. iptables -t mangle -N MYSHAPER-OUT
  34. iptables -t mangle -A POSTROUTING -o $DEV -j MYSHAPER-OUT
  35.  
  36. iptables -t mangle -A MYSHAPER-OUT -s 192.168.0.0/24 -j RETURN
  37.  
  38. # tcp ack gets high-prio
  39. #iptables -t mangle -A MYSHAPER-OUT -p tcp -m length --length :68 -j MARK --set-mark 10
  40. 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
  41. # so does icmp and udp
  42. iptables -t mangle -A MYSHAPER-OUT -p icmp -j MARK --set-mark 10
  43. iptables -t mangle -A MYSHAPER-OUT -p udp -j MARK --set-mark 10
  44. # defaults, get lower priority
  45. iptables -t mangle -A MYSHAPER-OUT -m mark --mark 0 -j MARK --set-mark 20
  46.  
  47. #iptables -t mangle -A MYSHAPER-OUT -p tcp -m length --length :64 -j CLASSIFY --set-class 1:10
  48. #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
  49. #iptables -t mangle -A MYSHAPER-OUT -p icmp -j CLASSIFY --set-class 1:10
  50. #iptables -t mangle -A MYSHAPER-OUT -p udp -j CLASSIFY --set-class 1:10
  51. #iptables -t mangle -A MYSHAPER-OUT -m mark --mark 0 -j CLASSIFY --set-class 1:20
  52.  
  53.  
  54. # http://www.knowplace.org/pages/howtos/traffic_shaping_with_linux/examples.php
  55. # http://trekweb.com/~jasonb/articles/traffic_shaping/scenarios.html
  56. # http://www.shorewall.net/traffic_shaping.htm
  57. # http://www.docum.org/docum.org/faq/cache/49.html