====== Limitation de bande passante ====== Ces 3 scripts sont basé sur l'outil tc, fourni dans le paquet iproute2. Ils utilisent le scheduler réseau HTB. Cet exemple traite d'une limitation de bande passante sur le port 80 de la machine hôte. #!/bin/sh # script /etc/init.d/limit-bandwidth # run the htb-* scripts to limit (or not) the bandwith # Author: Loïs # SCRDIR="/root/nyx/scripts" BINSTART="htb-start.sh" BINSTOP="htb-stop.sh" MODULE="sch_htb" ETH_DEV="eth0" # if scripts not present, stop & exit. test -x $SCRDIR/$BINSTART || exit 0 test -x $SCRDIR/$BINSTOP || exit 0 case "$1" in start) echo "starting HTB on eth0, port 80: " modprobe $MODULE sleep 2 $SCRDIR/$BINSTART echo "" ;; stop) echo "stopping HTB on eth0, port 80: " $SCRDIR/$BINSTOP modprobe -r $MODULE echo "" ;; restart) echo "restarting HTB on eth0, port 80: " $SCRDIR/$BINSTOP modprobe -r $MODULE sleep 2 modprobe $MODULE sleep 2 $SCRDIR/$BINSTART echo "" ;; status) echo "bandwith limits status: " tc -s qdisc show dev $ETH_DEV tc -s class show dev $ETH_DEV echo "" ;; *) echo "Limit the bandwidth apache2 use" echo "Usage: $0 {start|stop|restart|status}" echo "" exit 1 ;; esac exit 0 #!/bin/sh # htb-start.sh # Author: gentoo-wiki # change these values to suit your needs ETH_DEV="eth0" LINK_SPEED="2048Kbit" UPLOAD_SPEED="1024Kbit" PORT="80" # delete previous root node tc qdisc del dev $ETH_DEV root # create root node tc qdisc add dev $ETH_DEV root handle 1: htb default 11 # create LINK class tc class add dev $ETH_DEV parent 1: classid 1:1 htb rate $LINK_SPEED # create our HTTP shaping class tc class add dev $ETH_DEV parent 1:1 classid 1:10 htb rate $UPLOAD_SPEED # create our REST class for unutilized bandwidth tc class add dev $ETH_DEV parent 1:1 classid 1:11 htb rate $LINK_SPEED # create the filter for the HTTP class, we filter on source port 80 (http) tc filter add dev $ETH_DEV protocol ip parent 1:0 prio 1 u32 match ip sport $PORT 0xffff flowid 1:10 #!/bin/sh # htb-stop.sh # Author: gentoo-wiki ETH_DEV="eth0" tc qdisc del dev $ETH_DEV root