Qos & Tc
De BlaxWiki
Révision datée du 22 mars 2011 à 17:49 par 217.174.199.129 (discussion) (Page créée avec « Afin de restreinte le trafic, nous allons utiliser l'utilitaire TC qui fonctionne avec iptables. Ceci est le script d'init à envoyer au démarrage. <pre> #!/bin/bash # # t... »)
Afin de restreinte le trafic, nous allons utiliser l'utilitaire TC qui fonctionne avec iptables. Ceci est le script d'init à envoyer au démarrage.
#!/bin/bash
#
# tc uses the following units when passed as a parameter.
# kbps: Kilobytes per second
# mbps: Megabytes per second
# kbit: Kilobits per second
# mbit: Megabits per second
# bps: Bytes per second
# Amounts of data can be specified in:
# kb or k: Kilobytes
# mb or m: Megabytes
# mbit: Megabits
# kbit: Kilobits
# To get the byte figure from bits, divide the number by 8 bit
#
#
# Name of the traffic control command.
TC=/sbin/tc
# The network interface we're planning on limiting bandwidth.
IF=eth0 # Interface
# Download limit (in mega bits)
DNLD=400kbit # DOWNLOAD Limit
#
IPT="/sbin/iptables"
start() {
$IPT -t mangle -F
$TC qdisc add dev $IF root handle 1:0 htb default 30
$TC class add dev $IF parent 1:0 classid 1:10 htb rate $DNLD
$IPT -A OUTPUT -t mangle -p tcp --sport 80 -j MARK --set-mark 10
$TC filter add dev $IF parent 1:0 prio 0 protocol ip handle 10 fw
flowid 1:10
}
stop() {
# Stop the bandwidth shaping.
$TC qdisc del dev $IF root
$IPT --flush
}
restart() {
# Self-explanatory.
stop
sleep 1
start
}
show() {
# 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"
;;
show)
echo "Bandwidth shaping status for $IF:"
show
echo ""
;;
*)
pwd=$(pwd)
echo "Usage: tc.bash {start|stop|restart|show}"
;;
esac
exit 0