rendered paste body#!/bin/bash
#
#Declarando Variaveis
IF0='eth0'
IF1='eth1'
IF2='eth2'
IP_IF1=$(/sbin/ifconfig ${IF1} | awk '/inet addr:/ {print $2}' | cut -d: -f2)
IP_IF2=$(/sbin/ifconfig ${IF2} | awk '/inet addr:/ {print $2}' | cut -d: -f2)
GW_IF1='200.171.103.193'
GW_IF2='192.168.3.1'
REDE0='192.168.0.0/24'
REDE1='200.171.103.0/26'
REDE2='192.168.3.0/24'
IPTESTE='200.160.2.3'
IPTABLES=$(which iptables)
ROUTE=$(which route)
FPING=$(which fping)
SSL='443'
#route add -host $IPTESTE gw $GW_IF1
#TESTALINK1=$(fping -r 1 $IPTESTE |awk -F " " '{print $3}')
#route del -host $IPTESTE
#TESTALINK1=$(fping -r 1 $IPTESTE |awk -F " " '{print $3}')
#read
#Ajustando tabelas default
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 novas tabelas
echo "200 T1" >> /etc/iproute2/rt_tables
echo "201 T2" >> /etc/iproute2/rt_tables
#Resetando tabelas
ip route flush default
ip route flush table T1
ip route flush table T2
#Criando rotas paras novas tabelas
ip route add $REDE1 dev $IF1 src $IP_IF1 table T1
ip route add default via $GW_IF1 table T1
ip route add $REDE2 dev $IF2 src $IP_IF2 table T2
ip route add default via $GW_IF2 table T2
ip route add $REDE1 dev $IF1 src $IP_IF1
ip route add $REDE2 dev $IF2 src $IP_IF2
ip route add default via $GW_IF1
ip rule add from $IP_IF1 table T1
ip rule add from $IP_IF2 table T2
ip route add $REDE0 dev $IF0 table T1
ip route add $REDE2 dev $IF2 table T1
ip route add 127.0.0.0/8 dev lo table T1
ip route add $REDE0 dev $IF0 table T2
ip route add $REDE1 dev $IF1 table T2
ip route add 127.0.0.0/8 dev lo table T2
#Loadbalance
#Atenção caso tenha um limk mais potente que o outro mude a prioridade do mesmo pra "2"
ip route add default scope global nexthop via $GW_IF1 dev $IF1 weight 1 \
nexthop via $GW_IF2 dev $IF2 weight 1
##########################################
~# sh -x redundancia1.sh
+ IF0=eth0
+ IF1=eth1
+ IF2=eth2
++ /sbin/ifconfig eth1
++ awk '/inet addr:/ {print $2}'
++ cut -d: -f2
+ IP_IF1=200.171.103.214
++ /sbin/ifconfig eth2
++ awk '/inet addr:/ {print $2}'
++ cut -d: -f2
+ IP_IF2=192.168.3.55
+ GW_IF1=200.171.103.193
+ GW_IF2=192.168.3.1
+ REDE0=192.168.0.0/24
+ REDE1=200.171.103.0/26
+ REDE2=192.168.3.0/24
+ IPTESTE=200.160.2.3
++ which iptables
+ IPTABLES=/usr/sbin/iptables
++ which route
+ ROUTE=/sbin/route
++ which fping
+ FPING=/usr/sbin/fping
+ SSL=443
+ echo '255 local'
+ echo '254 main'
+ echo '253 default'
+ echo '0 unspec'
+ echo '200 T1'
+ echo '201 T2'
+ ip route flush default
+ ip route flush table T1
Nothing to flush.
+ ip route flush table T2
Nothing to flush.
+ ip route add 200.171.103.0/26 dev eth1 src 200.171.103.214 table T1
+ ip route add default via 200.171.103.193 table T1
RTNETLINK answers: No such process
+ ip route add 192.168.3.0/24 dev eth2 src 192.168.3.55 table T2
+ ip route add default via 192.168.3.1 table T2
RTNETLINK answers: No such process
+ ip route add 200.171.103.0/26 dev eth1 src 200.171.103.214
+ ip route add 192.168.3.0/24 dev eth2 src 192.168.3.55
+ ip route add default via 200.171.103.193
RTNETLINK answers: No such process
+ ip rule add from 200.171.103.214 table T1
+ ip rule add from 192.168.3.55 table T2
+ ip route add 192.168.0.0/24 dev eth0 table T1
+ ip route add 192.168.3.0/24 dev eth2 table T1
+ ip route add 127.0.0.0/8 dev lo table T1
+ ip route add 192.168.0.0/24 dev eth0 table T2
+ ip route add 200.171.103.0/26 dev eth1 table T2
+ ip route add 127.0.0.0/8 dev lo table T2
+ ip route add default scope global nexthop via 200.171.103.193 dev eth1 weight 1 nexthop via 192.168.3.1 dev eth2 weight 1
RTNETLINK answers: No such process