#!/bin/bash DEV="eth1" # interface to limit case $1 in start) echo "Starting bandwidth limiter..." tc qdisc add dev $DEV root handle 1: htb tc class add dev $DEV parent 1: classid 1:1 htb rate 100Mbit # interface speed tc class add dev $DEV parent 1:1 classid 1:10 htb rate 160Kbit # limit speed tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10 # you can match ports like this if you want...why? #tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip sport 2234 0xffff flowid 1:10 # This catches mark. Use if your IPTables doesn't support classify. Set with # -j MARK --set-mark 10 #tc filter add dev $DEV parent 1: protocol ip handle 10 fw flowid 1:10 # For a nat setup with slsk ports forwarded to another box this will work. #iptables -t mangle -A FORWARD -p tcp --sport 2234:2239 -j CLASSIFY --set-class 1:10 # To run this on the same box as museekd, this will do the trick. iptables -t mangle -A POSTROUTING -p tcp --sport 2234:2239 -j CLASSIFY --set-class 1:10 ;; stop) echo "Stopping bandwidth limiter..." tc qdisc del dev $DEV root 2>&1 >/dev/null # I just wipe the entire mangle table as this is the only stuff I have in it. # You may want to change this if you use the mangle table elsewhere. iptables -F -t mangle iptables -X -t mangle ;; restart) $0 stop $0 start ;; status) echo "[iptables - $DEV]" iptables -t mangle -L echo "------------------------" echo echo "[qdisc - $DEV]" tc -s qdisc show dev $DEV echo "------------------------" echo echo "[class - $DEV]" tc -s class show dev $DEV ;; filter) echo "[filter - $DEV]" tc -s filter show dev $DEV ;; *) echo 'Usage: {start|stop|restart|status}' ;; esac