Limitar ancho de banda con PrometheusQOS

Imagen de RazaMetaL

Tema: 

En mi búsqueda de una aplicación que me permita limitar anchos de banda por direcciones IP llegué hasta [url=http://www.arachne.cz/index.php?clanekid=231]PrometheusQoS[/url].

[quote]
Prometheus QoS (Quality of Service) is an ISP-oriented tool for easy manipulation of the IP traffic shaping and sharing features of the Linux kernel. It generates multiple nested HTB traffic control classes with fine-grained rate and ceiling values and implements optional daily (or simply periodical) data transfer quotas and data transfer statistics (as HTML). It is compatible with NAT (both asymmetric and symmetric), yet still provides good two-way shaping and prioritizing for both uploads and downloads.
[/quote]

Mis requerimientos son:
- Limitar anchos de banda por direcciones IP;
- Limitar anchos de banda por grupos de direcciones IP;
- Que sea fácil de administrar, esto porque quien va a administrar el servicio no voy a ser yo :)

Voy a describir como instalar y configurar PrometheusQoS para administrar los anchos de banda para los usuarios de mi red interna.

[b]Requisitos:[/b]
- Kernel 2.6 con soporte HTB y SFQ habilitados;

cat /boot/config-`uname -r` | grep CONFIG_NET_SCH_HTB && cat /boot/config-`uname -r` | grep CONFIG_NET_SCH_SFQ
CONFIG_NET_SCH_HTB=m
CONFIG_NET_SCH_SFQ=m

- Debian GNU/Linux, aunque se puede instalar prometheus en cualquier otra distro, si alguien lo hace que me avise para actualizar este manual ;)
- La instalación se hará como usuario root;

[b]Instalación:[/b]
Descargamos PrometheusQoS:

cd /usr/src/
wget http://www.arachne.cz/download/prometheus-0.7.8.tar.gz

Creamos un paquete deb y lo instalamos:

aptitude -y install debhelper build-essential debian-builder
cd /usr/src/
tar zvxf prometheus-0.7.8.tar.gz
cd prometheus-0.7.8
make deb
dpkg -i prometheus_0.7.8-1_i386.deb

[b]Configuración:[/b]
La configuración la podemos encontrar en /etc/prometheus y consta de dos archivos:

/etc/prometheus/prometheus.conf
/etc/prometheus/hosts

El primero va a contener los "planes" que vamos a ofrecer a los usuarios y el segundo especifica a que plan pertenece cada uno.

Supongamos que vamos a tener dos tipos de "planes":

- 1024kbps compartido entre 2 usuarios, con un mínimo de 512kbps y máximo de 1024kbps
- 512kbps compartido entre 8 usuarios, con un mínimo de 64kbps y máximo de 512kbps

Nuestros archivos de configuración ser verían así:
/etc/prometheus/prometheus.conf

#==========================================================================
#
# Prometheus QoS - steal fire from your ISP !
# "fair-per-IP" quality of service utility
# requires Linux kernel with HTB qdisc enabled
# GNUpyright(G)2007 Michael xChaos Polak, x@n.cz
# Credits: CZFree.Net / Freegate / Deu / d@n.cz
# ...and Martin Devera for his HTB, of course ;-)
#
#==========================================================================
#Path to external utilities required to run iGW Prometheus:
#--------------------------------------------------------------------------
tc /sbin/tc
iptables /sbin/iptables
iptables-restore /sbin/iptables-restore
#==========================================================================
#Filename of iptables mangle table for iptables-restore
#--------------------------------------------------------------------------
iptables-file /var/spool/prometheus.iptables
#==========================================================================
#Filename of /etc/hosts - style IP address configuration file
#--------------------------------------------------------------------------
hosts /etc/prometheus/hosts
#==========================================================================
#Keywords found in /etc/host comments - syntax KEYWORD-MIN-MAX
#Eg.: 192.168.1.2 mypc #internet-256-512
#sets HTB rate for 192.168.1.2 to 256 kbps and HTB ceil to 512 kbps
#--------------------------------------------------------------------------
keyword internet512-8a1
keyword internet1024-2a1

#==========================================================================
#LAN (local, downstream) and WN (isp, internet, upstream) interface names
#didn't work well with only one interface - two interfaces are required now
#--------------------------------------------------------------------------
lan-interface eth1 #Linux network interface name
wan-interface eth0 #Linux network interface name
#==========================================================================
#LAN and WAN medium definition (100Mbit, 10Mbit - use 2Mbit for Wi-Fi)
#--------------------------------------------------------------------------
lan-medium 100Mbit #Mbit|kbit
wan-medium 100Mbit #Mbit|kbit
#==========================================================================
#guranted upload and download bandwidth FROM your ISP (in kbps, please!)
#asymetry settings will be automaticaly calculated from these values
#--------------------------------------------------------------------------
wan-download 2048 #kbps
wan-upload 2048 #kbps
#==========================================================================
#special QoS free zone (eg. free CZFree tranzit, etc.)
#Apply QoS on HTTP proxy IP addres/port
#Set HTB rate and HTB ceil for address undefined in hosts file
#--------------------------------------------------------------------------
qos-free-zone 0 #0=disable|subnet eg. 192.168.0.0/16
qos-free-delay 14400 #seconds to wait before applying QoS
qos-proxy-enable 1 #1=yes|0=no
qos-proxy-ip 192.168.0.1/32 #eg. IP of our LAN interface
qos-proxy-port 3128 #squid port
free-rate 64 #kbps - by Vitex kuli testovani dashboardu
free-ceil 128 #kbps
digital-divide-weirdness-ratio 1 #can be 1, 2, 3, maybe even more...
#==========================================================================
#Asymetric line settings - this allows setup of ADSL-style ISP service
#asymetry-rate 2 means upload is limited to 50% of the rate of download
#asymetry-treshold 64 means upload will be 64 kbps slower then download
#--------------------------------------------------------------------------
#These settings are keyword-derived ! (see "keyword" section)
#--------------------------------------------------------------------------
internet512-8a1-asymetry-ratio 1 #2,4,etc. for relative upload shaping
internet512-8a1-asymetry-treshold 0 #kbps
internet1024-8a1-asymetry-ratio 2
internet1024-8a1-asymetry-treshold 0
#==========================================================================
#HTB fine tuning part I - common settings
#--------------------------------------------------------------------------
htb-nesting-limit 3 #0..4: HTB seems to have built-in limit
htb-burst 8 #kbit (ip level classes)
htb-burst-group 32 #kbit (group level classes)
htb-burst-main 64 #kbit (medium&line level classes - 1:1, 1:2)
htb-leaf-discipline sfq perturb 5 #maybe "none"
htb-r2q 1
#type filtering traffic: mark&filter or classify (without tc filter)
filter-type classify #or mark
#==========================================================================
#magic-include-upload - is data counter sum of upload and download ?
#magic-treshold - heaviest downloader: htb-rate, 2nd: htb-rate+magic-treshold
#==========================================================================
magic-include-upload 1 #1=yes|0=no
magic-treshold 2 #kbps
#--------------------------------------------------------------------------
#Magic data limit based od guaranted bandwidth in kbps fine tunes HTB ceil:
#(magic-relative-limit)*(min bandwidth kbps) = limit for given time period
#eg. value 8 gives 512 MB limit to 64 kbps HTB rates, 1024 MB to 128'ers...
#magic-fixed-limit is fixed data limit in MB (megabytes), 0=no limit
#HTB ceil will be reduced to (HTB rate) for the most unfair-users
#other offenders get (HTB rate)+(magic-treshold)
#magic-relative-prio and magic-fixed-prio work exactly the same way as
#limit, except that they reduce HTB priority instead of HTB ceil
#--------------------------------------------------------------------------
#These settings are keyword-derived ! (see "keyword" section)
#--------------------------------------------------------------------------
internet512-8a1-magic-relative-limit 8 #*kb/sec->MB/day
internet512-8a1-magic-relative-prio 6 #*kb/sec->MB/day
internet512-8a1-magic-fixed-limit 0 #MB, less then
internet512-8a1-magic-fixed-prio 0 #MB, less then
internet1024-2a1-magic-relative-limit 12
internet1024-2a1-magic-relative-prio 8
internet1024-2a1-magic-fixed-limit 0
internet1024-2a1-magic-fixed-prio 0
#==========================================================================
#HTB fine tuning part II - keyword dependent settings
#--------------------------------------------------------------------------
#These settings are keyword-derived ! (see "keyword" section)
#--------------------------------------------------------------------------
internet512-8a1-htb-default-prio 1 #can be 1...7
internet512-8a1-htb-rate-bonus 0 #kbps
internet512-8a1-htb-ceil-malus 0 #kbps
internet1024-2a1-htb-default-prio 1
internet1024-2a1-htb-rate-bonus 16
internet1024-2a1-htb-ceil-malus 0
#==========================================================================
#HTB fine tuning part III - keyword dependent settings
#--------------------------------------------------------------------------
#These settings are keyword-derived ! (see "keyword" section)
# optionally! if not defined, using global leaf-discipline
# value "none" skip qdisc creation for this keyword
#--------------------------------------------------------------------------
#internet512-8a1-leaf-leaf-discipline esfq
#internet1024-2a1-leaf-discipline none
#==========================================================================
#Credit file settings - stores unused credit from previous runs
#--------------------------------------------------------------------------
credit-filename /var/lib/misc/prometheus.credit
credit-enable 1 #1=yes|0=no
#==========================================================================
#Log file names and directories
#--------------------------------------------------------------------------
log-filename /var/log/prometheuslog
log-traffic-directory /var/www/logs/
log-traffic-html-directory /var/www/logs/html/
log-traffic-url-path logs/
#==========================================================================
#Hall of Fame - Greatest Suckers settings
#--------------------------------------------------------------------------
hall-of-fame-enable 1 #1=yes|0=no
hall-of-fame-filename /var/www/yesterday.html
hall-of-fame-preview /var/www/today.html
hall-of-fame-title Hall of Fame - Greatest Suckers
#==========================================================================
#Hall of Fame - Color settings (for FUP data limit display)
#--------------------------------------------------------------------------
#These settings are keyword-derived ! (see "keyword" section)
#--------------------------------------------------------------------------
internet512-8a1-html-color 008000
internet1024-2a1-html-color 000080
#==========================================================================
#That's all, folks. Now just run /usr/sbin/prometheus every day...

Como podrán apreciar, en el archivo de configuración hemos definido los nombres de los planes que vamos a ofrecer:

internet512-8a1
internet1024-2a1

Entre otras cosas también se ha especificado:

wan-download Ancho de banda de bajada que tenemos disponible para distribuir
wan-upload Ancho de banda de subida que tenemos disponible para distribuir
lan-interface Interfaz LAN, generalmente eth1
wan-interface Interfaz WAN, generalmetne eth0
lan-medium Velocidad de la tarjeta de red LAN (10Mbit, 100Mbit, etc)
wan-medium Velocidad de la tarjeta de red WAN (10Mbit, 100Mbit, etc)

Ahora debemos definir cuales son los usuarios que van a estar en cada plan:
/etc/prometheus/hosts

# use TABs to separate IP address, hostname, and speed definition!
# this file is just dummy example not related to prometheus.conf.SAMPLE
# see sample-configuration/hosts to learn more about what Prometheus QoS can handle

# syntax: "via-prometheus-MIN-MAX", where MIN and MAX are values in kbps
# "sharing-HOSTNAME" is useful to aggregate more IPs in single traffic class

# note, that keywords parsed by Prometheus QoS look like ordinary comments to tools
# used to process bsd-style /etc/hosts file...

192.168.0.0 redclientes #(solo informacion - nombre de la red)
192.168.0.1 linux #(solo informacion - interfaz interna del linux)
192.168.0.2 pcmonitoreo #sharing-linux
192.168.0.3 pcrazametal #sharing-linux

# Clientes plan 512kbps
# En ancho de banda mínimo cuando todos esten conectados será de 64kbps
# y el máximo de 512kbps
192.168.0.101 cliente1 #internet512-8a1-64-512
192.168.0.102 cliente2 #sharing-cliente1
192.168.0.103 cliente3 #sharing-cliente1
192.168.0.104 cliente4 #sharing-cliente1
192.168.0.105 cliente5 #sharing-cliente1
192.168.0.106 cliente6 #sharing-cliente1
192.168.0.107 cliente7 #sharing-cliente1
192.168.0.108 cliente8 #sharing-cliente1

# Clientes plan 1024kbps
# En ancho de banda mínimo cuando todos esten conectados será de 512kbps
# y el máximo de 1024kbps
192.168.0.201 cliente9 #internet1024-2a1-512-1024
192.168.0.202 cliente10 #sharing-cliente9

Habilitamos el arranque de PromethusQoS y nuestras configuración cuando reiniciemos el servidor:
vi /etc/default/prometheus

# Run prometheus on startup
PROMETHEUS_ENABLE=yes

Iniciamos prometheus:

/etc/init.d/prometheus start

Prometheus nos mostrará los clientes y a que plan estan asociados:

Prometheus QoS - "fair-per-IP" Quality of Service setup utility.
Version 0.7.8 - Copyright (C)2005-2008 Michael Polak (xChaos)
iptables-restore & burst tunning & classify modification 0.7d by Ludva
Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf

Parsing configuration file /etc/prometheus/prometheus.conf ...
Configured keywords: via-prometheus internet512-8a1 internet1024-2a1
Parsing iptables verbose output ...
Parsing class defintion file /etc/prometheus/hosts ...
Resolving shared connections ...
Unresolved shared connection: 192.168.0.3 pcrazametal sharing-linux
Unresolved shared connection: 192.168.0.2 pcmonitoreo sharing-linux
Parsing credit file /var/lib/misc/prometheus.credit ...
Initializing iptables and tc classes ...
Running /sbin/iptables-restore

[b]Para tener en cuenta:[/b]
La unidad utilizada en /etc/prometheus/prometheus.conf es el kilobit y no el kilobyte (1 byte = 8 bits).
El archivo /etc/prometheus/hosts utiliza espacios de tabulador entre la dirección IP, nombre de cliente y plan.
Podemos utlizar prometheus -p para obtener una top10 de consumo de cada cliente.

Comentarios

Buen como Raza, esa es, tengo

Imagen de damage

Buen como Raza, esa es, tengo 2 dudas primera, sebes si se puede utilizar más de 1 LAN osea tener 2LAN y 1 WAN?, segudo, como reconoce el script a que grupo corresponde una ip o un grupo eso no me quedo muy claro.
Saludos brother.

Cita: Buen como Raza, esa

Imagen de RazaMetaL

[quote]
Buen como Raza, esa es, tengo 2 dudas primera, sebes si se puede utilizar más de 1 LAN osea tener 2LAN y 1 WAN?,
[/quote]

Si puedes usar 2 LAN, pero no se si en mas de una tarjeta de red.

[quote]
segudo, como reconoce el script a que grupo corresponde una ip o un grupo eso no me quedo muy claro.
[/quote]

Eso lo defines en el archivo /etc/prometheus/hosts .

-----

Visita este [url=http://www.sindominio.net/ayuda/preguntas-inteligentes.html]link[/url] :evil:

[img]http://www.bbspot.com/Images/News_Features/2003/01/os_quiz/debian.jpg[/img]

(adsbygoogle = window.adsbygoogle || []).push({});

mmm, muy interesante esta

Imagen de The One

mmm, muy interesante esta herramienta, raza solo una pregunta, esta herramienta tiene interfaz web, o conoces algo parecido a este "Prometheus" con interfaz de configuración web y que se pueda segmentar por grupo de usuarios o grupo de ips tal como pones en la configuración, por ejemplo dar un canal de 256 6:1 o 2:1 ???

Eso es lo que yo estaba

Imagen de RazaMetaL

Eso es lo que yo estaba buscando :)

Prometheus te muestra una especie de site con estadísticas del consumo, yo no lo utilizo y no sabría decirte que tan efectiva es la información que despliega.

No estoy seguro, pero creo que htb-gen permite configuración via web browser.

-----

Visita este [url=http://www.sindominio.net/ayuda/preguntas-inteligentes.html]link[/url] :evil:

[img]http://www.bbspot.com/Images/News_Features/2003/01/os_quiz/debian.jpg[/img]

(adsbygoogle = window.adsbygoogle || []).push({});

mmm, sigo buscando una

Imagen de The One

mmm, sigo buscando una herramienta buena que haga lo que hace este Prometheus pero que sea de configuraciòn http, si la encuentras no te olvides de pasarla, o si alguien sabe de alguna.

Asegurate de que shorewall no

Imagen de RazaMetaL

Asegurate de que shorewall no haga flush de la tabla mangle que es utilizada por Prometheus.

-----

Visita este [url=http://www.sindominio.net/ayuda/preguntas-inteligentes.html]link[/url] :evil:

[img]http://www.bbspot.com/Images/News_Features/2003/01/os_quiz/debian.jpg[/img]

(adsbygoogle = window.adsbygoogle || []).push({});

Hola RazaMetal, puedes

Imagen de nino1511

Hola

RazaMetal, puedes esplicar como agrupo a los clientes 8 a 1? no entiendo como quedan agrupados, por más que leo no noto el agrupamiento, voy a seguir leyendo para ver como me va igual por favor trata de aclararlo.

También nos puedes esplicar como hacer QoS, como hago prioridad al puerto 80, y quitarle prioridad al p2p, por favor si no es mucha la molestía.

Saludos

Vamos Ecuador, si se puede

Tengo una duda más, cuando

Imagen de nino1511

Tengo una duda más, cuando mido el ancho de la subida, ESTE SCRIPT NO LA LIMITA
lan-interface eth1 #Linux network interface name ASI NO ME LIMITA LA SUBIDA
wan-interface eth0 #Linux network interface name

LA ETH1 EN MI CASO ES LA RED LOCAL Y ETH0 ES LA WAN
cuando invierto los los valores así:
lan-interface eth0
wan-interface eth1

Así límito la subida pero no totalmente explico:
si le pongo de ancho 512kbit 2a1 mide de subida entre 64kbit y 128kbit
pero la bajada si llega a 512kbit
que estoy haciendo mal, claro que esto esta siendo probado con el redireccionamiento hacia el squid.

Saludos
Nota: esto también me pasa con htb-gen y cbq, no puedo limitar la subida si redirecciono hacia el squid osea del 80 al 3128.
uso 5.2 centos

Vamos Ecuador, si se puede

Páginas