Ver Feed RSS

wps

LoadBalance

Avalie este Post de Blog
LoadBalance Totalmente funcional, não ta fazendo fail over.

#!/bin/sh

IPT=/usr/sbin/iptables
REDA=192.168.0.0/24
GWA=192.168.0.1
IFA="eth0"

#CONFIGURACAO DO LINK A JATO
gw0="189.4.152.201" #GATEWAY
ln0="189.4.152.202" #LINK
if0="eth1"
tb0="lnk1"
ng0="189.4.152.0/24"

#CONFIGURACAO DO LINK A speedy !! uma porcaria
gw1="200.3.154.1" #GATEWAY
ln1="200.3.154.3" #LINK
if1="eth2"
tb1="lnk2"
ng1="200.3.154.0/24"

start(){

echo "Limpando as rotas padroes"
ip route del default via $gw0 > /dev/null
ip route del default via $gw1 > /dev/null

route del default gw $gw0 metric 1
route del default gw $gw1 metric 0

route del default gw $gw0 metric 0
route del default gw $gw1 metric 1
echo ""

echo "Limpando as tabela de roteamento"
ip route flush table $tb0
ip route flush table $tb1
echo ""

echo "Adicionando rotas de Pacotes"
ip route add $REDA dev $IFA src $GWA table $tb0
ip route add $ng0 dev $if0 src $ln0 table $tb0
ip route add 127.0.0.0/8 dev lo table $tb0

#ip route add default via $gw0 table $tb0
echo ""

echo "SEGUNDA TABELA"
ip route add $REDA dev $IFA src $GWA table $tb1
ip route add $ng1 dev $if1 src $ln1 table $tb1
ip route add 127.0.0.0/8 dev lo table $tb1

#ip route add default via $gw1 table $tb1
echo ""

echo "Adicionando regra nas tabelas dos links"
ip rule add from $ng0 table $tb0
ip rule add from $ng1 table $tb1
echo ""

echo "Adicionando regra nas tabelas dos links"
ip rule add from $REDA table $tb0
ip rule add from $REDA table $tb1
echo ""

echo "Adicionando o BALANCEAMENTO"
ip route add default scope global nexthop via $gw0 dev $if0 weight 1 nexthop via $gw1 dev $if1 weight 1
echo ""

echo "Limpando o cache de roteamento"
ip route flush cache
echo ""

echo "refazendo o nat"
$IPT -t mangle -F
$IPT -t nat -F POSTROUTING

$IPT -t nat -A POSTROUTING -s $REDA -o $if0 -j SNAT --to $ln0
$IPT -t nat -A POSTROUTING -s $REDA -o $if1 -j SNAT --to $ln1
}

stop(){

echo "REMOVENDO regra nas tabelas dos links"
ip rule del from $ng0 table $tb0
ip rule del from $ng1 table $tb1
echo ""

echo "REMOVENDO regra nas tabelas dos links"
ip rule del from $REDA table $tb0
ip rule del from $REDA table $tb1
echo ""

echo "LIPANDO AS TABELAS DE ROTAS"
ip route flush table $tb0
ip route flush table $tb1
echo ""

echo "PARANDO O ROTEAMENTO AVANCADO !!!"
$IPT -F -t mangle
echo " Limpando as rotas padroes"
ip route del default via $gw0 > /dev/null
ip route del default via $gw1 > /dev/null

route del default gw $gw0 metric 1
route del default gw $gw1 metric 0

route del default gw $gw0 metric 0
route del default gw $gw1 metric 1

echo ""

echo " Limpando as tabela de roteamento"
ip route flush table $tb0
ip route flush table $tb1
echo ""

echo "ADICIONANDO ROTAS DEFAULTS"
ip route add default via $gw0 metric 1
ip route add default via $gw1 metric 0
}

case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
*)
echo "usage $0 start|stop|restart"
esac

Atualizado 11-07-2008 em 14:07 por wps

Categorias
Não Categorizado

Comentários


+ Enviar Comentário