#!/bin/bash # # Tous les débits sont en Kbits, donc pour récuperer des kilo-octets(Ko), divisez ce chiffre par 8 # ex: 25Kbps == 3.125KB/s # TC=/sbin/tc DNLD=150Kbit # Limite de download DWEIGHT=15Kbit # coefficient de DOWNLOAD (Weight Factor) ~ 1/10 of DOWNLOAD Limit UPLD=25KBit # Limite d'upload Limit UWEIGHT=2Kbit # Coefficient d'UPLOAD (Weight Factor) tc_start() { $TC qdisc add dev eth0 root handle 11: cbq bandwidth 100Mbit avpkt 1000 mpu 64 $TC class add dev eth0 parent 11:0 classid 11:1 cbq rate $DNLD weight $DWEIGHT allot 1514 prio 1 avpkt 1000 bounded $TC filter add dev eth0 parent 11:0 protocol ip handle 4 fw flowid 11:1 $TC qdisc add dev eth1 root handle 10: cbq bandwidth 10Mbit avpkt 1000 mpu 64 $TC class add dev eth1 parent 10:0 classid 10:1 cbq rate $UPLD weight $UWEIGHT allot 1514 prio 1 avpkt 1000 bounded $TC filter add dev eth1 parent 10:0 protocol ip handle 3 fw flowid 10:1 } tc_stop() { $TC qdisc del dev eth0 root $TC qdisc del dev eth1 root } tc_restart() { tc_stop sleep 1 tc_start } tc_show() { echo "" echo "eth0:" $TC qdisc show dev eth0 $TC class show dev eth0 $TC filter show dev eth0 echo "" echo "eth1:" $TC qdisc show dev eth1 $TC class show dev eth1 $TC filter show dev eth1 echo "" } case "$1" in start) echo -n "Starting bandwidth shaping: " tc_start echo "done" ;; stop) echo -n "Stopping bandwidth shaping: " tc_stop echo "done" ;; restart) echo -n "Restarting bandwidth shaping: " tc_restart echo "done" ;; show) tc_show ;; *) echo "Usage: /etc/init.d/tc.sh {start|stop|restart|show}" ;; esac exit 0 |
$TC qdisc add dev eth0 root handle
11: cbq bandwidth 100Mbit avpkt 1000 mpu 64 $TC class add dev eth0 parent 11:0 classid 11:1 cbq rate $DNLD weight $DWEIGHT allot 1514 prio 1 avpkt 1000 bounded $TC filter add dev eth0 parent 11:0 protocol ip handle 4 fw flowid 11:1 $TC qdisc add dev eth1 root handle 10: cbq bandwidth 10Mbit avpkt 1000 mpu 64 $TC class add dev eth1 parent 10:0 classid 10:1 cbq rate $UPLD weight $UWEIGHT allot 1514 prio 1 avpkt 1000 bounded $TC filter add dev eth1 parent 10:0 protocol ip handle 3 fw flowid 10:1 |
# Marque les packets # Marquage des packets en upload $IPTABLES -t mangle -A FORWARD -s 192.168.0.128/29 -j MARK --set-mark 3 $IPTABLES -t mangle -A FORWARD -s 192.168.0.6 -j MARK --set-mark 3 # Marquage des packets en download $IPTABLES -t mangle -A FORWARD -s ! 192.168.0.0/24 -d 192.168.0.128/29 -j MARK --set-mark 4 $IPTABLES -t mangle -A FORWARD -s ! 192.168.0.0/24 -d 192.168.0.6 -j MARK --set-mark 4 |