[FUG-BR] RES: Balance usando PF

Leandro - Intersol listas em intersolinformatica.com.br
Quinta Julho 14 11:41:35 BRT 2011


Bom dia 

Desculpe a demora, mas estranhamente eu não estava recebendo e-mails da FUG

Então achei em um help, creio que seja bem "gambi" mas pra mim deu certo hehehehe

no caso das diferenças de valores eu não usei o prob, porque ele segura o prob %, ou seja bloqueia
e passa a diferença, não tenho certeza se estou falando certo, mas em meus testes deu isso 
daí eu joguei o gateway mais uma vez na saída onde eu queria a saída maior e voi-lá deu certo hehehehe
sei que é gambi, mas deu certinho pra mim 

aos mais conhecedores posso estar falando bobeira demais, mas funcionou pra mim 


exemplo 
## Inicio do PF
lan_net = "192.168.0.0/16"
int_if  = "rl0"
ext_if1 = "fxp0"
ext_if2 = "age0"
ext_if3 = "rl1"
ext_gw1 = "189.5.5.1"
ext_gw2 = "192.168.4.1"
ext_gw3 = "192.168.3.1"

# Opcoes
set timeout { interval 10, frag 30 }
set timeout { tcp.first 90, tcp.opening 30, tcp.established 86400 }
set timeout { tcp.closing 900, tcp.finwait 45, tcp.closed 90 }
set timeout { udp.first 60, udp.single 30, udp.multiple 60 }
set timeout { icmp.first 60, icmp.error 30 }
set timeout { other.first 60, other.single 30, other.multiple 60 }
set timeout { adaptive.start 0, adaptive.end 0 }
set limit { states 10000, frags 5000 }
set loginterface $ext_if1
set optimization aggressive
set block-policy drop
set require-order yes
set skip on lo0

# Scrub para todas as interfaces para pacotes fragmentos perdidos
scrub in  all
scrub out  all

# Faz nat em conexões de saída, em ambas as interfaces da Internet
nat on $ext_if1 from $lan_net to any -> ($ext_if1)
nat on $ext_if2 from $lan_net to any -> ($ext_if2)
nat on $ext_if3 from $lan_net to any -> ($ext_if3)

# Passa todo o tráfego de saída na interface interna
pass out on $int_if from any to $lan_net

# Aceita e passa direto quaisquer pacotes destinados ao próprio gateway
pass in quick on $int_if from $lan_net to $int_if

# Faz balanceamento de carga no tráfego TCP de saída da rede interna.
pass in on $int_if route-to \
    { ($ext_if1 $ext_gw1), ($ext_if1 $ext_gw1), ($ext_if1 $ext_gw1), ($ext_if1 $ext_gw1), ($ext_if1 $ext_gw1), ($ext_if1 $ext_gw1), ($ext_if2 $ext_gw2), ($ext_if3 $ext_gw3) } round-robin \
    proto tcp from $lan_net to any flags S/SA modulate state

# Balanceamento de carga em tráfego udp e icmp vindo da rede interna
pass in on $int_if route-to \
    { ($ext_if1 $ext_gw1), ($ext_if1 $ext_gw1), ($ext_if1 $ext_gw1), ($ext_if1 $ext_gw1), ($ext_if1 $ext_gw1), ($ext_if1 $ext_gw1), ($ext_if2 $ext_gw2), ($ext_if3 $ext_gw3) } round-robin \
    proto { udp, icmp } from $lan_net to any keep state

#servicos que nao podem ser balanceados
#https
pass in on $int_if \
    route-to ($ext_if1 $ext_gw1) \
                proto tcp from $lan_net to any port 443

#msn
pass in on $int_if \
    route-to ($ext_if1 $ext_gw1) \
                proto tcp from $lan_net to any port 1863

#ftp
pass in on $int_if \
    route-to ($ext_if1 $ext_gw1) \
                proto tcp from $lan_net to any port {20, 21}

#ssh
pass in on $int_if \
    route-to ($ext_if1 $ext_gw1) \
                proto tcp from $lan_net to any port 22

# Regras gerais de permissão de tráfego de saída para as
# interfaces externas
pass out on $ext_if1 proto tcp from any to any flags S/SA modulate state
pass out on $ext_if1 proto { udp, icmp } from any to any keep state
pass out on $ext_if2 proto tcp from any to any flags S/SA modulate state
pass out on $ext_if2 proto { udp, icmp } from any to any keep state

# Roteia pacotes de quaisquer IPs na $ext_if1 para $ext_gw1, e faz
# o mesmo para $ext_if2 e $ext_gw2

pass out on $ext_if1 route-to ($ext_if2 $ext_gw2) from $ext_if2 to any
pass out on $ext_if1 route-to ($ext_if3 $ext_gw3) from $ext_if3 to any
pass out on $ext_if2 route-to ($ext_if1 $ext_gw1) from $ext_if1 to any
pass out on $ext_if2 route-to ($ext_if3 $ext_gw3) from $ext_if3 to any
pass out on $ext_if3 route-to ($ext_if1 $ext_gw1) from $ext_if2 to any
pass out on $ext_if3 route-to ($ext_if2 $ext_gw2) from $ext_if1 to any

## Fim do PF





> -----Mensagem original-----
> De: freebsd-bounces em fug.com.br [mailto:freebsd-bounces em fug.com.br]
> Em nome de Luiz Gustavo S. Costa
> Enviada em: terça-feira, 12 de julho de 2011 22:03
> Para: Mario Lobo
> Cc: freebsd em fug.com.br
> Assunto: Re: [FUG-BR] Balance usando PF
> 
> olha o exemplo que tem do icmp logo abaixo do paragrafo do man
> 
> 2011/7/12 Mario Lobo <lobo em bsd.com.br>:
> > On Tuesday 12 July 2011 20:10:45 Luiz Gustavo S. Costa wrote:
> >
> >> consertando a regra:
> >
> >>
> >
> >> pass in log quick on $int_if route-to ($ext_if1 $ext_gw1) from
> >
> >> $int_if:network to any propability 30%
> >
> >> pass in log quick on $int_if route-to ($ext_if2 $ext_gw2) from
> >
> >> $int_if:network to any
> >
> >>
> >
> >> 2011/7/12 Luiz Gustavo S. Costa <luizgustavo em luizgustavo.pro.br>:
> >
> >> > No caso do probability, você faz um route-to para cada link
> >
> >> >
> >
> >> >> pass in log quick on $int_if route-to { ($ext_if1 $ext_gw1),
> >> >> ($ext_if2 \
> >
> >> >> $ext_gw2) } round-robin from $int_if:network to any flags S/SA
> >> >> keep
> >
> >> >> state
> >
> >> >
> >
> >> > assim:
> >
> >> >
> >
> >> > pass in log quick on $int_if route-to ($ext_if1 $ext_gw1) from
> >
> >> > $int_if:network to any propability 30%
> >
> >> > pass in log quick on $int_if route-to ($ext_if1 $ext_gw1) from
> >
> >> > $int_if:network to any
> >
> >> >
> >
> >> > o que não passar pelo os 30% de um, cai nos 70% do outro (não
> >> > precisa
> >
> >> > especificar o probability na segunda, porque 30% das conexões já
> >> > caem
> >
> >> > na primeira, portanto, sobrando 70% para a outra)
> >
> >> >
> >
> >> > abraços
> >
> > Legal Luiz !!
> >
> > Uma última dúvida: a notação é esta mesmo? x %? Porque no man diz
> assim:
> >
> > probability ⟨number⟩
> >
> > A probability attribute can be attached to a rule, with a value set
> >
> > between 0 and 1, bounds not included.
> >
> > No caso, nao teria que ser como abaixo?
> >
> > pass in log quick on $int_if route-to ($ext_if1 $ext_gw1) from
> >
> > $int_if:network to any propability 0.3 ?
> >
> > Ou pode usar percentual mesmo?
> >
> > Muito obrigado mais uma vez.
> >
> > Abraços,
> >
> > --
> >
> > Mario Lobo
> >
> > http://www.mallavoodoo.com.br
> >
> > FreeBSD since 2.2.8 [not Pro-Audio.... YET!!] (99% winblows FREE)
> 
> 
> 
> --
>   /\             Luiz Gustavo S. Costa
>  /  \            Programmer at BSD Perimeter /    \ /\/\/\    Visit the pfSense Project
> /      \    \ \   http://www.pfsense.org
> ---------------------------------------------------------------------
> BSD da serra carioca, Teresopolis (visite: http://miud.in/Inv)
> Contatos: luizgustavo em luizgustavo.pro.br / lgcosta em pfsense.org
> Blog: http://www.luizgustavo.pro.br
> -------------------------
> Histórico: http://www.fug.com.br/historico/html/freebsd/
> Sair da lista: https://www.fug.com.br/mailman/listinfo/freebsd



Mais detalhes sobre a lista de discussão freebsd