Eu segui o tutorial daqui da underlinux
https://under-linux.org/content/view/4291/58/
Mas quando dou um tcpdump para verificar se está ocorrendo o "Load Balance" está errado, ele usa o link errado para conectar com a internet, segue-se meus scripts:
SCRITP IPTABLES
============================================
#!/bin/sh
##################################################
# Script criado por #
# Rodrigo Gustavo Gallacci #
# Complemento da firewall com #
# Balanco de cargas entre 2 links #
##################################################
##################################################
# Bloco de Variaveis #
##################################################
export REDE=192.168.1.0/24
export PLACA_INTERNA=eth1
export PLACA_SPEEDY=eth0
export PLACA_VIRTUA=eth2
export IP_SPEEDY=200.xxx.xxx.xxx
export IP_VIRTUA=201.xxx.xxx.xxx
export IP_INT=192.168.1.1
export HTTP=192.168.1.7
export GRAZIELA=192.168.1.211
export SERVIDOR05=192.168.1.5
export SERVIDOR_FDRJ=200.xxx.xxx.xxx
export SERASA=200.xxx.xxx.xxx
export rodrigo=192.168.1.201
export VIRTUA=1
export SPEEDY=2
export BALANCO=3
declare PORTA_REDIRECIONAMENTO[8]=(25 53 110 21 1863 3340 3342 5330)
##################################################
# Acionando redirecionamento de ip #
##################################################
echo 1 > /proc/sys/net/ipv4/ip_forward
##################################################
# Carregando modulos necessarios #
##################################################
depmod -a
modprobe ip_nat_ftp
modprobe ip_conntrack_ftp
modprobe ipt_MASQUERADE
modprobe ip_gre
modprobe ipt_LOG
#####################################################
# Limpando as regras anteriores #
#####################################################
iptables -F
iptables -t nat -F
iptables -X
iptables -X -t nat
iptables -Z
######################################################
# Criando as configuracoes da VPN com a Federacao Rio#
######################################################
ifconfig fdrj down
iptunnel del fdrj
######################################################
# Setando as politicas internas #
######################################################
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
######################################################
# Rotas e redirecionamentos #
######################################################
iptables -A PREROUTING -t nat -p tcp --dport 80 -i $PLACA_VIRTUA -d $IP_VIRTUA -j DNAT --to $HTTP:80
iptables -A PREROUTING -t nat -p tcp --dport 2080 -i $PLACA_VIRTUA -d $IP_VIRTUA -j DNAT --to $HTTP:2080
iptables -A PREROUTING -t nat -p tcp --dport 8080 -i $PLACA_VIRTUA -d $IP_VIRTUA -j DNAT --to $HTTP:8080
######################################################
# Rotas solicitadas pela Graziela #
######################################################
iptables -A PREROUTING -t nat -p tcp -i $PLACA_VIRTUA -d $IP_VIRTUA --dport 3342 -j DNAT --to $GRAZIELA:3342
iptables -A PREROUTING -t nat -p tcp -i $PLACA_VIRTUA -d $IP_VIRTUA --dport 3340 -j DNAT --to $GRAZIELA:3340
iptables -A PREROUTING -t nat -p tcp -i $PLACA_VIRTUA -d $IP_VIRTUA --dport 5330 -j DNAT --to $GRAZIELA:5330
######################################################
# Mascarando o ip interno para saida na internet #
######################################################
iptables -A POSTROUTING -t nat -o $PLACA_INTERNA -s $REDE -j MASQUERADE
######################################################
# Acertando o balanceamento dos pacotes #
######################################################
######################################################
# Regras de saida pelo Speedy #
######################################################
iptables -t mangle -A OUTPUT -p tcp -s $REDE --dport 21 -j MARK --set-mark $SPEEDY
iptables -t mangle -A OUTPUT -p tcp -s $REDE --dport 25 -j MARK --set-mark $SPEEDY
iptables -t mangle -A OUTPUT -p tcp -s $REDE --dport 80 -j MARK --set-mark $SPEEDY
iptables -t mangle -A OUTPUT -p tcp -s $REDE --dport 110 -j MARK --set-mark $SPEEDY
######################################################
# Regras de saida pelo Virtua #
######################################################
iptables -t mangle -A OUTPUT -p udp -s $REDE --dport 53 -j MARK --set-mark $VIRTUA
iptables -t mangle -A OUTPUT -p tcp -s $REDE --dport 1521 -j MARK --set-mark $VIRTUA
######################################################
# Caso seja necessario o balancemanto de carga #
######################################################
iptables -t mangle -A OUTPUT -p tcp -s $rodrigo -j MARK --set-mark $BALANCO
iptables -t mangle -A OUTPUT -p udp -s $rodrigo -j MARK --set-mark $BALANCO
######################################################
# Relacao de portas aceitas no redirecionamento #
######################################################
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -p icmp -s $REDE -j ACCEPT
######################################################
# Loop das portas gerais #
######################################################
for (( i = 0; i <= 7; i++ ))
do
iptables -A FORWARD -p tcp -i $PLACA_INTERNA --dport ${PORTA_REDIRECIONAMENTO[$i]} -j ACCEPT
iptables -A FORWARD -p udp -i $PLACA_INTERNA --dport ${PORTA_REDIRECIONAMENTO[$i]} -j ACCEPT
done
######################################################
# Portas e protocolos abertos especificamente #
######################################################
iptables -A FORWARD -p tcp -d $HTTP -i $PLACA_VIRTUA --dport 80 -j ACCEPT #Porta de http
iptables -A FORWARD -p tcp -d $HTTP -i $PLACA_VIRTUA --dport 2080 -j ACCEPT #Porta de http
iptables -A FORWARD -p tcp -d $HTTP -i $PLACA_VIRTUA --dport 8080 -j ACCEPT #Porta de http
iptables -A FORWARD -p tcp -s $HTTP -i $PLACA_VIRTUA --dport 80 -j ACCEPT #Porta de http
iptables -A FORWARD -p tcp -s $HTTP -i $PLACA_VIRTUA --dport 2080 -j ACCEPT #Porta de http
iptables -A FORWARD -p tcp -s $HTTP -i $PLACA_VIRTUA --dport 8080 -j ACCEPT #Porta de http
iptables -A FORWARD -p tcp -d $SERASA -o $PLACA_VIRTUA --dport 3335 -j ACCEPT #SERASA
######################################################
# Portas abertas para entrada #
######################################################
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p icmp -d ! $IP_SPEEDY -j ACCEPT
iptables -A INPUT -p icmp -d ! $IP_VIRTUA -j ACCEPT
iptables -A INPUT -s 127.0.0.1/24 -j ACCEPT
iptables -A INPUT -p tcp -s $SERVIDOR -j ACCEPT
iptables -A INPUT -p udp -s $SERVIDOR -j ACCEPT
iptables -A INPUT -p tcp -s $REDE --dport 4480 -j ACCEPT
iptables -A INPUT -p udp -s $REDE --dport 4480 -j ACCEPT
######################################################
# Configuracao para a VPN com a Federacao Rio #
######################################################
iptunnel add fdrj mode gre remote 200.255.249.2 local $IP_VIRTUA
ifconfig fdrj up 10.100.99.2 netmask 255.255.255.252
route add -net 10.0.0.0/8 gw 10.100.99.1
######################################################
# Portas e protocolo 47 para VPN com a Federacao Rio #
######################################################
iptables -A FORWARD -p 47 -j ACCEPT
iptables -A INPUT -p udp -s $SERVIDOR_FDRJ -i $PLACA_VIRTUA --dport 500 -j ACCEPT
iptables -A INPUT -p udp -s $SERVIDOR_FDRJ -i $PLACA_VIRTUA --dport 4500 -j ACCEPT
iptables -A INPUT -p esp -j ACCEPT
######################################################
# Gerando log das tentativas de acesso #
######################################################
# iptables -A INPUT -i $PLACA_SPEEDY -m state --state NEW,INVALID -j LOG --log-prefix "TENTATIVA_EXTERNA_SPEEDY" --log-level 6
# iptables -A INPUT -i $PLACA_SPEEDY -m state --state NEW,INVALID -j DROP
# iptables -A INPUT -i $PLACA_VIRTUA -m state --state NEW,INVALID -j LOG --log-prefix "TENTATIVA_EXTERNA_VIRTUA" --log-level 6
# iptables -A INPUT -i $PLACA_VIRTUA -m state --state NEW,INVALID -j DROP
# iptables -A INPUT -p tcp --syn -j LOG --log-prefix "OUTRAS_TENTATIVAS" --log-level 6
# iptables -A INPUT -p tcp --syn -j DROP
#####################################################
# Para testes no firewall #
#####################################################
iptables -A FORWARD -p tcp -s $rodrigo -j ACCEPT
iptables -A INPUT -p tcp -s $rodrigo -j ACCEPT
iptables -A OUTPUT -p tcp -s $rodrigo -j ACCEPT
#####################################################
# Abilitando as portas para redirecionamento #
# dos clientes. #
#####################################################
for i in `ls /root/firewall/status`
do
echo "FECHADO" > /root/firewall/status/$i
done
##################################################
# Fim do Script #
##################################################
SCRIPT DAS ROTAS
========================================
#!/bin/sh
##################################################
# Script criado originalmente por #
#
[email protected] editado por #
# Rodrigo Gustavo Gallacci #
##################################################
echo "Inicializando procedimento de rotas"
##################################################
# RESETANDO TABELAS DE ROTAS, PADRAO DO SISTEMA #
##################################################
echo "255 local" > /etc/iproute2/rt_tables
echo "254 main" >> /etc/iproute2/rt_tables
echo "253 default" >> /etc/iproute2/rt_tables
echo "0 unspec" >> /etc/iproute2/rt_tables
##################################################
# ADICIONANDO OUTRAS TABELAS #
##################################################
echo "200 router1" >> /etc/iproute2/rt_tables
echo "201 router2" >> /etc/iproute2/rt_tables
echo "202 router3" >> /etc/iproute2/rt_tables
echo " declarando variaveis"
GATE1=201.xxx.xxx.xxx #Gateway Virtua
LINK1=201.xxx.xxx.xxx #IP Virtua
PLACA_LINK1=eth2 #Placa de rede Virtua
GATE2=200.xxx.xxx.xxx #Gateway Speedy
LINK2=200.xxx.xxx.xxx #IP Speedy
PLACA_LINK2=eth0 #Placa de rede Speedy
##################################################
# RESETANDO AS TABELAS #
##################################################
echo " resetando as tabelas"
ip route flush table router1
ip route flush table router2
ip route flush table router3
##################################################
# CRIANDO A TABELA 1 PARA VIRTUA #
##################################################
echo " criando a tabela 1"
ip route show table main | grep -v ^default | while read ROUTE ; do
ip route add table router1 $ROUTE
done
ip route add $LINK1 via $GATE1 table router1
ip route add default via $GATE1 table router1
##################################################
# CRIANDO A TABELA 2 PARA SPEEDY #
##################################################
echo " criando a tabela 2"
ip route show table main | grep -v ^default | while read ROUTE ; do
ip route add table router2 $ROUTE
done
ip route add $LINK2 via $GATE2 table router2
ip route add default via $GATE2 table router2
##################################################
# CRIANDO A TABELA 3 PARA BALANCEAMENTO DE CARGAS#
##################################################
echo " criando a tabela 3"
ip route add default table router3 nexthop dev $PLACA_LINK2 via $GATE1 weight 1 nexthop dev $PLACA_LINK2 via $GATE2 weight 1
# CRIANDO AS REGRAS
echo " criando regras"
ip rule add from $LINK1 table router1 prio 26
ip rule add from $LINK2 table router2 prio 27
ip rule add fwmark 1 table router1 prio 29
ip rule add fwmark 2 table router2 prio 30
ip rule add fwmark 3 table router3 prio 25
# LIMPANDO CACHE
echo " limpando cache"
ip route flush cache
#Fim do Script
Aonde estou errando???:(
Mesmo eu indicando que a porta 80 deve sair com "Mark" 2 que é o do Speedy, ele continua saindo pelo Virtua, alguma dica?
Agradeço antecipadamente.