+ Responder ao Tópico



  1. #1

    Padrão IPFW não esta limitando velocidade!!!!

    Olá pessoal!!! estou com problemas na limitação de banda para os clientes via IPFW do FreeBSD 5.3. Quando meço a velocidade de conexao do cliente no gratis bate la em cima, tipo 460kbps, 680kbps... sendo que no servidor estão todos barrados em 240kbps. vou postar meu ipfw.rules ai em baixo. Se alguem puder me ajudar, desde ja agradeço a atenção.

    ipfw -f flush
    natd -s -p 8668 -n tun0
    ipfw add 10 divert natd all from any to any via tun0
    ipfw add 11 allow all from any to any via tun0
    ipfw add 12 permit all from any to any via rl1
    ipfw add 13 deny udp from any to any 137
    ipfw add 14 deny udp from any to any 138
    ipfw add 15 deny udp from any to any 139
    ipfw add 16 fwd 127.0.0.1,3128 tcp from 192.168.0.0/24 to any 80

    ipfw add 20 allow ip from 192.168.0.1 to any
    ipfw add 21 allow ip from any to 192.168.0.1
    ipfw add 22 allow ip from 192.168.0.2 to any
    ipfw add 23 allow ip from any to 192.168.0.2
    ipfw add 24 allow ip from 192.168.0.3 to any
    ipfw add 25 allow ip from any to 192.168.0.3
    ipfw add 26 allow ip from 192.168.0.4 to any
    ipfw add 27 allow ip from any to 192.168.0.4
    ipfw add 28 allow ip from 192.168.0.5 to any
    ipfw add 29 allow ip from any to 192.168.0.5

    ipfw pipe 1 config bw 240Kbit/s queue 10
    ipfw pipe 2 config bw 75Kbit/s queue 10
    ipfw add 100 pipe 1 ip from any to 192.168.0.8/30 out via rl1
    ipfw add 105 pipe 2 ip from 192.168.0.8/30 to any in via rl1

    ipfw pipe 3 config bw 240Kbit/s queue 10
    ipfw pipe 4 config bw 75Kbit/s queue 10
    ipfw add 110 pipe 3 ip from any to 192.168.0.12/30 out via rl1
    ipfw add 115 pipe 4 ip from 192.168.0.12/30 to any in via rl1

    ipfw pipe 5 config bw 240Kbit/s queue 10
    ipfw pipe 6 config bw 75Kbit/s queue 10
    ipfw add 120 pipe 5 ip from any to 192.168.0.16/30 out via rl1
    ipfw add 125 pipe 6 ip from 192.168.0.16/30 to any in via rl1

    ipfw pipe 7 config bw 240Kbit/s queue 10
    ipfw pipe 8 config bw 75Kbit/s queue 10
    ipfw add 130 pipe 7 ip from any to 192.168.0.20/30 out via rl1
    ipfw add 135 pipe 8 ip from 192.168.0.20/30 to any in via rl1

    ipfw pipe 9 config bw 240Kbit/s queue 10
    ipfw pipe 10 config bw 75Kbit/s queue 10
    ipfw add 140 pipe 9 ip from any to 192.168.0.24/30 out via rl1
    ipfw add 145 pipe 10 ip from 192.168.0.24/30 to any in via rl1

    tenho tambem o incoveniente de para cada cliente na rede eu ter que colocar essas 4 linhas no ipfw.rules. Sera que eu poderia limitar toda minha rede para a velocidade "X" sem precisar colocar esse tanto de pipes? Pessoal sou novato na area.. relevem......
    Aguardo respostas passoal !!! Forte abraço.

  2. #2

    Padrão Re: IPFW não esta limitando velocidade!!!!

    Cabra ... que bagunça esse teu ipfw.rules hein ?
    Pega esse exemplo ae e modifica de acordo com tuas necessidades:

    /sbin/ipfw -f flush
    /sbin/ipfw add divert natd all from any to any via vr0
    /sbin/ipfw add pass all from any to any


    #clientes 256k
    /sbin/ipfw add 0011 pipe 20 tcp from any to 192.168.1.0/24 out
    /sbin/ipfw add 0010 pipe 21 tcp from 192.168.59.0/24 to any in
    /sbin/ipfw pipe 20 config bw 256kbit/s queue 10kbytes
    /sbin/ipfw pipe 21 config bw 256kbit/s queue 10kbytes

    #clientes 128k
    /sbin/ipfw add 0013 pipe 22 tcp from any to 192.168.16.0/24 out
    /sbin/ipfw add 0012 pipe 23 tcp from 192.168.160.0/24 to any in
    /sbin/ipfw pipe 22 config bw 128kbit/s queue 10kbytes
    /sbin/ipfw pipe 23 config bw 128kbit/s queue 10kbytes


    *Observe que o controle de banda está sendo feito por faixas de ip ok !? e lembre-se do "pipe" :mrgreen:
    *Ia esquecendo, no bloqueio das portas 135-139 que vc fez, nao esqueça de incluir o tcp e a porta 445, ou entao vai ser só festa pelo ms-netbios :mrgreen:

  3. #3

    Padrão Re: IPFW não esta limitando velocidade!!!!

    Bagunça está esse seu exemplo...
    Do jeito que voce colocou os pipes, a rede 1 iria compartilhar 256k para todos os ips da rede, e a rede 16 (ou 160), iria compartilhar128k entre eles....
    rss..

  4. #4

    Padrão Re: IPFW não esta limitando velocidade!!!!

    Esse nosso amigo grayfox e sempre muito engraçado !!! hehehe

    # limpando as chains existentes
    /sbin/ipfw -f flush

    #Bloqueando NetBios
    /sbin/ipfw add 100 deny log tcp from any to any 135
    /sbin/ipfw add 101 deny log tcp from any to any 136
    /sbin/ipfw add 102 deny log tcp from any to any 137
    /sbin/ipfw add 103 deny log tcp from any to any 138
    /sbin/ipfw add 104 deny log tcp from any to any 139
    /sbin/ipfw add 105 deny log udp from any to any 135
    /sbin/ipfw add 106 deny log udp from any to any 136
    /sbin/ipfw add 107 deny log udp from any to any 137
    /sbin/ipfw add 108 deny log udp from any to any 138
    /sbin/ipfw add 109 deny log udp from any to any 139
    /sbin/ipfw add 110 deny log tcp from any 135 to any
    /sbin/ipfw add 111 deny log tcp from any 136 to any
    /sbin/ipfw add 112 deny log tcp from any 137 to any
    /sbin/ipfw add 113 deny log tcp from any 138 to any
    /sbin/ipfw add 114 deny log tcp from any 139 to any
    /sbin/ipfw add 115 deny log udp from any 135 to any
    /sbin/ipfw add 116 deny log udp from any 136 to any
    /sbin/ipfw add 117 deny log udp from any 137 to any
    /sbin/ipfw add 118 deny log udp from any 138 to any
    /sbin/ipfw add 119 deny log udp from any 139 to any
    /sbin/ipfw add 120 deny log tcp from any to any 445
    /sbin/ipfw add 121 deny log tcp from any 445 to any
    /sbin/ipfw add 122 deny log udp from any to any 445
    /sbin/ipfw add 123 deny log udp from any 445 to any

    #Limitando a velocidade de down e up do ip 192.168.0.10
    /sbin/ipfw add 1 pipe 3 tcp from any to 192.168.0.10 out
    /sbin/ipfw add 1 pipe 4 tcp from 192.168.0.10 to any in
    /sbin/ipfw pipe 3 config bw 128kbit/s queue 10kbytes
    /sbin/ipfw pipe 4 config bw 64kbit/s queue 10kbytes

    #Fecha o resto
    /sbin/ipfw add 1 pipe 5 tcp from any to 192.168.0.0:255.255.255.0 out
    /sbin/ipfw add 1 pipe 6 tcp from 192.168.0.0:255.255.255.0 to any in
    /sbin/ipfw pipe 5 config bw 1bit/s queue 10kbytes
    /sbin/ipfw pipe 6 config bw 1bit/s queue 10kbytes

    Crie sempre 4 linhas de controle pra cada ip como no exemplo acima !!!

    Valeu



  5. #5

    Padrão Re: IPFW não esta limitando velocidade!!!!

    Simplificando tudo isso ai em cima, mas com controle por mac address junto.
    (ultimamente, muita gente me pergunta porque que nao funciona o controle por mac address, seguindo isso aqui, vao ver que funciona.. rss..)

    Vou usar o mesmo "layout" do amigo gatao

    Para habilitar o suporte a camada 2, coloque em /etc/sysctl.conf :
    net.link.ether.ipfw=1

    Ou entao, coloque na mao mesmo:
    sysctl net.link.ether.ipfw=1

    #desativando passagem unica (nao esquecer!)
    /sbin/ipfw disable one_pass

    # limpando as chains existentes
    /sbin/ipfw -f flush

    #Bloqueando NetBios
    /sbin/ipfw add 100 deny log all from any 135-139,445 to any
    /sbin/ipfw add 101 deny log all from any to any 135-139,445

    #Limitando a velocidade de down e up do rede 192.168.10 toda. (todos os ips vao ter upload de 64 e download de 128.

    /sbin/ipfw pipe 1 mask src-ip 0x000000ff bw 64Kbps queue 5.4
    /sbin/ipfw pipe 2 mask dst-ip 0x000000ff bw 128Kbps queue 10.6

    #Definindo os pipes para a rede.
    add 100 pipe 1 all from 192.168.10.0/24 to any in layer2
    add 101 pipe 2 all from any to 192.168.10.0/24 out layer2

    #Definindo quem pode trafegar ( IP X MAC )
    ## 192.168.10.5
    add 200 allow all from any to 192.168.10.5 MAC 00:01:02:03:04:05 any layer2
    add 201 allow all from 192.168.10.5 to any MAC any 00:01:02:03:04:05 layer2

    ## 192.168.10.8
    add 202 allow all from any to 192.168.10.8 MAC 00:05:04:03:02:01 any layer2
    add 203 allow all from 192.168.10.8 to any MAC any 00:05:04:03:02:01 layer2

    #fechando tudo
    add 65000 deny all from any to any layer2


    Estamos com o basico do basico aí.
    Se nao for usar o controle para mac address, tire a opcao do sysctl, ou defina pra 0
    e remova dessas regras, esse layer2 do lado.

    Sem mais,






  6. #6

    Padrão Re: IPFW não esta limitando velocidade!!!!

    gostei da maneira como simplificou o bloqueio referente a netbios grayfox !!!

    Muito joia a dica !!!


  7. #7

    Padrão Re: IPFW não esta limitando velocidade!!!!

    E outra ainda, muita gente me procura pra saber como q funcionam as queues, slots, coisa do genero...

    Quem quiser, preste atencao que é bem simples calcular os slots...

    Exemplo:

    P: Como calcular a queue (em slots) de um link de 512K ?

    R: 1 - Converter o 512KBits/s para KBytes: 512/8 = 64KBytes
    2 - Dividir o 64 por 1.5 ( o 1.5 eh da mtu )

    Simplificando:

    512/8 = 64
    64/1.5 = 42.66666666666667

    Resposta: 42.7

    pipe 1 config bw 512kbit/s queue 42.7


    vamoss dominarrr o mondoo00000!!!