henriqcabral
(usa Ubuntu)
Enviado em 12/06/2012 - 16:19h
######################## DEFINICOES LINK 1
IP1=192.168.0.242
NET1=192.168.0.0/24
GW1=192.168.0.148
TAB1=link1
WG1=1
IFACE1=eth1
######################## DEFINICOES LINK 2
IP2=200.206.216.189
NET2=200.206.216.0/24
GW2=200.206.216.129
TAB2=link2
WG2=1
IFACE2=eth2
######################## DEFINICOES DE TABELAS DE ROTEAMENTO
TAB1=link1
TAB2=link2
########################---- Modulos
echo "Ativando modulos Gerais"
echo 1 > /proc/sys/net/ipv4/ip_forward
########################---- IPTABLES
echo "Preparando roteamento"
echo "...Configurando Masquerade"
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE
########################----Define politicas padrao
echo "...Definindo politicas padrao"
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
########################----Ativando modulos
echo "...Ativando modulos"
modprobe ipt_mark
modprobe ipt_MARK
modprobe ip_tables
modprobe iptable_nat
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
modprobe ipt_LOG
modprobe ipt_REJECT
modprobe ipt_MASQUERADE
#########################----LIMPA IPTABLES
iptables -t nat -F
iptables -t nat -X
iptables -F
iptables -X
iptables -t mangle -F
iptables -t mangle -X
##########################----LIMPA TABELAS
echo "...Limpando Tablea de roteamento"
ip rule flush 2> /dev/null
ip route del default 2> /dev/null
ip rule add prio 32765 lookup main 2> /dev/null
ip rule add prio 32767 lookup default 2> /dev/null
ip route flush cache 2> /dev/null
ip route flush table $TAB1 #Limpa as rotas no cache da tabela 1
ip route flush table $TAB2 #Limpa as rotas no cache da tabela 2
##########################----REFAZENDO AS ROTAS
ip route add $NET1 dev $IFACE1 src $IP1 table $TAB1
ip route add default via $GW1 table $TAB1
ip route add $NET2 dev $IFACE2 src $IP2 table $TAB2
ip route add default via $GW2 table $TAB2
ip rule add from $IP1 table $TAB1
ip rule add from $IP2 table $TAB2
ip route add default scope global nexthop via $GW1 dev $IFACE1 weight $WG1 nexthop via $GW2 dev $IFACE2 weight $WG2
####################################################
echo "...Habilitando roteamento"
for i in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo "0" > $i
done
echo "...Configurando regras de roteamento IPTABLES"
####----CRIANDO AS MARCACOES
echo "......Adicionando marcacoes"
ip rule add fwmark 1 lookup link1 prio 1
ip rule add fwmark 2 lookup link2 prio 1