#!/bin/bash
#adiciono as tabelas em iproute
echo "100 T1" >> /etc/iproute2/rt_tables
echo "101 T2" >> /etc/iproute2/rt_tables
#link da BRT
IF1='eth0'
#link da GVT
IF2='eth2'
#gateway da GVT
P1='192.168.2.253'
#gateway da BRT
P2='192.168.1.254'
#redes quem pertencem os gateways
P1_NET='192.168.1.0'
P2_NET='192.168.2.0'
#adiciono as rotas
ip route add $P1_NET dev $IF1 src $IF1 table T1
ip route add default via $P1 table T1
ip route add $P2_NET dev $IF2 src $IF2 table T2
ip route add default via $P2 table T2
#formo a main routing table
ip route add $P1_NET dev $IF1 src $IF1
ip route add $P2_NET dev $IF2 src $IF2
#adiciono uma rota prefencial pra poder utilizar um gerenciador de downloads
ip route add default via $P1
#agora tem que setar as regras de de roteamenta pra a escolha das tabelas
ip rule add from $IF1 table T1
ip rule add from $IF2 table T2
#agora tem que fazer o balanceamento de carga
ip route add default scope global nexthop via $P1 dev $IF1 weight 1 \
nexthop via $P2 dev $IF2 weight 1
#desabilito o rp_filter
echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter