Newsgroup: it.comp.os.linux.iniziare
Titolo: traffic shaping

ciao
ho un serverino che gestisce diversi servizi (web,ftp,ssh etc etc)
vorrei mettere su un sistema di traffic shaping (penso si dica così) che
mi permetta di:
1.non impazzire a farlo.
2.definire delle specie di priorità.
Nel senso che se c'è solo un servizio attivo quello se ne ha bisogno si
prende anche tutta la banda; se ce ne sono due quello con priorità + alta
si prende tutta la banda che gli serve; se sono 3 il primo piglia quello
che serve, il secondo quello che serve dopo che ha preso il primo e il
terzo quello che rimane se qualcosa rimane.
3.Se possibile, impostare una banda minima per certi servizi se e solo se 
questo viene usato.
Mi basta un link / how-to.
Grazie

 Mi basta un link / how-to.
http://wiki.gentoo-italia.net/index.php/Limitare_la_banda



ottimo grazie

ho provato a fare uno script che va ma...
non da i risultati sperati.
Io vorrei che le classi con prirità minore possano mangiare
tutta la banda a quelle con priorità maggiore fino eventualemnte ad
arrivare a un minimo o anche a lasciarle a zero ma questo non succede.
HELP
#!/bin/bash
iptables -F
#iptables -A INPUT -p tcp -m osf --log 0 #logga os
#iptables -A INPUT -m ipv4options --any-opt -j LOG --log-ip-options --log-prefix "FW:IPopt:" # logga pakketti con strani ip option
##################################################################################################################
#
#					DA QUI SOTTO CE SOLO TRAFFIC SHAPING
#
##################################################################################################################
# NOTE: The following configuration works well for my 
# setup: 1.5M/128K ADSL via Pacific Bell Internet (SBC Global Services)
DEV=eth0
RATEUP=240	#256
# 
# End Configuration Options
#
# Reset everything to a known state (cleared)
tc qdisc del dev $DEV root    2> /dev/null > /dev/null
tc qdisc del dev imq0 root 2> /dev/null > /dev/null
iptables -t mangle -D POSTROUTING -o $DEV -j MYSHAPER-OUT 2> /dev/null > /dev/null
iptables -t mangle -F MYSHAPER-OUT 2> /dev/null > /dev/null
iptables -t mangle -X MYSHAPER-OUT 2> /dev/null > /dev/null
#iptables -t mangle -D PREROUTING -i $DEV -j MYSHAPER-IN 2> /dev/null > /dev/null
#iptables -t mangle -F MYSHAPER-IN 2> /dev/null > /dev/null
#iptables -t mangle -X MYSHAPER-IN 2> /dev/null > /dev/null
ip link set imq0 down 2> /dev/null > /dev/null
rmmod imq 2> /dev/null > /dev/null
###########################################################
#
# Outbound Shaping (limits total bandwidth to RATEUP)
# set queue size to give latency of about 2 seconds on low-prio packets
#ip link set dev $DEV qlen 30
# changes mtu on the outbound device.  Lowering the mtu will result
# in lower latency but will also cause slightly lower throughput due 
# to IP and TCP protocol overhead.
#ip link set dev $DEV mtu 1000
# add HTB root qdisc
tc qdisc add dev $DEV root handle 1: htb default 26
# add main rate limit classes
tc class add dev $DEV parent 1: classid 1:1 htb rate 100Mbit
# add leaf classes - We grant each class at LEAST it's "fair share" of bandwidth.
#                    this way no class will ever be starved by another class.  Each
#                    class is also permitted to consume all of the available bandwidth
#                    if no other classes are in use.
tc class add dev $DEV parent 1:1 classid 1:20 htb rate 100Mbit prio 0
tc class add dev $DEV parent 1:1 classid 1:21 htb rate 240kbit prio 1
tc class add dev $DEV parent 1:1 classid 1:22 htb rate 240kbit prio 2
tc class add dev $DEV parent 1:1 classid 1:23 htb rate 240kbit prio 3
tc class add dev $DEV parent 1:1 classid 1:24 htb rate 240kbit prio 4
tc class add dev $DEV parent 1:1 classid 1:25 htb rate 240kbit prio 5
tc class add dev $DEV parent 1:1 classid 1:26 htb rate 240kbit prio 6
# attach qdisc to leaf classes - here we at SFQ to each priority class.  SFQ insures that
#                                within each class connections will be treated (almost) fairly.
tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
tc qdisc add dev $DEV parent 1:21 handle 21: sfq perturb 10
tc qdisc add dev $DEV parent 1:22 handle 22: sfq perturb 10
tc qdisc add dev $DEV parent 1:23 handle 23: sfq perturb 10
tc qdisc add dev $DEV parent 1:24 handle 24: sfq perturb 10
tc qdisc add dev $DEV parent 1:25 handle 25: sfq perturb 10
tc qdisc add dev $DEV parent 1:26 handle 26: sfq perturb 10
# filter traffic into classes by fwmark - here we direct traffic into priority class according to
#                                         the fwmark set on the packet (we set fwmark with iptables
#                                         later).  Note that above we've set the default priority
#                                         class to 1:26 so unmarked packets (or packets marked with
#                                         unfamiliar IDs) will be defaulted to the lowest priority
#                                         class.
tc filter add dev $DEV parent 1:0 prio 0 protocol ip handle 20 fw flowid 1:20
tc filter add dev $DEV parent 1:0 prio 0 protocol ip handle 21 fw flowid 1:21
tc filter add dev $DEV parent 1:0 prio 0 protocol ip handle 22 fw flowid 1:22
tc filter add dev $DEV parent 1:0 prio 0 protocol ip handle 23 fw flowid 1:23
tc filter add dev $DEV parent 1:0 prio 0 protocol ip handle 24 fw flowid 1:24
tc filter add dev $DEV parent 1:0 prio 0 protocol ip handle 25 fw flowid 1:25
tc filter add dev $DEV parent 1:0 prio 0 protocol ip handle 26 fw flowid 1:26
# add MYSHAPER-OUT chain to the mangle table in iptables - this sets up the table we'll use
#                                                      to filter and mark packets.
iptables -t mangle -N MYSHAPER-OUT
iptables -t mangle -I POSTROUTING -o $DEV -j MYSHAPER-OUT
# add fwmark entries to classify different types of traffic - Set fwmark from 20-26 according to
#                                                             desired class. 20 is highest prio.
#iptables -t mangle -A MYSHAPER-OUT -p tcp --sport 0:1024 -j MARK --set-mark 22 # NFS 
#iptables -t mangle -A MYSHAPER-OUT -p tcp --dport 0:1024 -j MARK --set-mark 22 # NFS 
iptables -t mangle -A MYSHAPER-OUT -p tcp --dport 20 -j MARK --set-mark 25     # ftp-data port, low prio
iptables -t mangle -A MYSHAPER-OUT -p tcp --sport 20 -j MARK --set-mark 25     # ftp-data port, low prio
#iptables -t mangle -A MYSHAPER-OUT -p tcp --dport 5190 -j MARK --set-mark 23   # aol instant messenger
#iptables -t mangle -A MYSHAPER-OUT -p icmp -j MARK --set-mark 26               # ICMP (ping) - high prio, impress friends
iptables -t mangle -A MYSHAPER-OUT -p udp --dport 53 -j MARK --set-mark 21      # DNS name resolution (small packets)
iptables -t mangle -A MYSHAPER-OUT -p udp --sport 53 -j MARK --set-mark 21      # DNS name resolution (small packets)
iptables -t mangle -A MYSHAPER-OUT -p tcp --dport ssh -j MARK --set-mark 23    # secure shell
iptables -t mangle -A MYSHAPER-OUT -p tcp --sport ssh -j MARK --set-mark 23    # secure shell
#iptables -t mangle -A MYSHAPER-OUT -p tcp --dport telnet -j MARK --set-mark 22 # telnet (ew...)
#iptables -t mangle -A MYSHAPER-OUT -p tcp --sport telnet -j MARK --set-mark 22 # telnet (ew...)
#iptables -t mangle -A MYSHAPER-OUT -p ipv6-crypt -j MARK --set-mark 24         # IPSec - we don't know what the payload is though...
iptables -t mangle -A MYSHAPER-OUT -p tcp --sport http -j MARK --set-mark 24   # Local web server
#iptables -t mangle -A MYSHAPER-OUT -p tcp -m length --length :64 -j MARK --set-mark 21 # small packets (probably just ACKs)
iptables -t mangle -A MYSHAPER-OUT -p tcp --tcp-flags ACK ACK -j MARK --set-mark 22
iptables -t mangle -A MYSHAPER-OUT -m mark --mark 0 -j MARK --set-mark 26      # redundant- mark any unmarked packets as 26 (low prio)
iptables -t mangle -A MYSHAPER-OUT -d 192.168.1.3 -j MARK --set-mark 20 # Default for subnet 
iptables -t mangle -A MYSHAPER-OUT -s 192.168.1.3 -j MARK --set-mark 20 #
Default for subnet