Guest User

Maiquel

a guest
Jul 22nd, 2011
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #!/bin/bash
  2. IF="eth0"
  3. TC=/sbin/tc
  4. IPTABLES=/sbin/iptables
  5. REM="-D"
  6. ADD="-A"
  7.  
  8.  
  9.  
  10. start() {
  11.  
  12. $TC qdisc add dev eth0 root handle 1:0 htb default 10
  13. $TC class add dev eth0 parent 1:0 classid 1:10 htb rate 20kbps ceil 20kbps prio 0
  14. $IPTABLES $ADD OUTPUT -t mangle -p tcp --sport 80 -j MARK --set-mark 10
  15. $TC filter add dev eth0 parent 1:0 prio 0 protocol ip handle 10 fw flowid 1:10
  16.  
  17. }
  18. stop() {
  19.  
  20. # Stop the bandwidth shaping.
  21. $TC qdisc del dev $IF root
  22. $IPTABLES $REM OUTPUT -t mangle -p tcp --sport 80 -j MARK --set-mark 10
  23.  
  24. }
  25.  
  26. restart() {
  27.  
  28. # Self-explanatory.
  29. stop
  30. sleep 1
  31. start
  32.  
  33. }
  34.  
  35. status() {
  36.  
  37. # Display status of traffic control status.
  38. $TC -s qdisc ls dev $IF
  39.  
  40. }
  41.  
  42. case "$1" in
  43.  
  44. start)
  45.  
  46. echo -n "Starting bandwidth shaping: "
  47. start
  48. echo "done"
  49. ;;
  50.  
  51. stop)
  52.  
  53. echo -n "Stopping bandwidth shaping: "
  54. stop
  55.  
  56. echo "done"
  57. ;;
  58.  
  59. restart)
  60.  
  61. echo -n "Restarting bandwidth shaping: "
  62. restart
  63. echo "done"
  64. ;;
  65.  
  66. status)
  67.  
  68. echo "Bandwidth shaping status for $IF:"
  69. status
  70. echo ""
  71. ;;
  72.  
  73. *)
  74.  
  75. pwd=$(pwd)
  76. echo "Usage: tc.bash {start|stop|restart|status}"
  77. ;;
  78.  
  79. esac
  80.  
  81. exit 0
Advertisement
Add Comment
Please, Sign In to add comment