Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- IF="eth0"
- TC=/sbin/tc
- IPTABLES=/sbin/iptables
- REM="-D"
- ADD="-A"
- start() {
- $TC qdisc add dev eth0 root handle 1:0 htb default 10
- $TC class add dev eth0 parent 1:0 classid 1:10 htb rate 20kbps ceil 20kbps prio 0
- $IPTABLES $ADD OUTPUT -t mangle -p tcp --sport 80 -j MARK --set-mark 10
- $TC filter add dev eth0 parent 1:0 prio 0 protocol ip handle 10 fw flowid 1:10
- }
- stop() {
- # Stop the bandwidth shaping.
- $TC qdisc del dev $IF root
- $IPTABLES $REM OUTPUT -t mangle -p tcp --sport 80 -j MARK --set-mark 10
- }
- restart() {
- # Self-explanatory.
- stop
- sleep 1
- start
- }
- status() {
- # Display status of traffic control status.
- $TC -s qdisc ls dev $IF
- }
- case "$1" in
- start)
- echo -n "Starting bandwidth shaping: "
- start
- echo "done"
- ;;
- stop)
- echo -n "Stopping bandwidth shaping: "
- stop
- echo "done"
- ;;
- restart)
- echo -n "Restarting bandwidth shaping: "
- restart
- echo "done"
- ;;
- status)
- echo "Bandwidth shaping status for $IF:"
- status
- echo ""
- ;;
- *)
- pwd=$(pwd)
- echo "Usage: tc.bash {start|stop|restart|status}"
- ;;
- esac
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment