All pastes #631031 Raw Edit

Unnamed

public text v1 · immutable
#631031 ·published 2007-07-23 17:35 UTC
rendered paste body
#!/bin/bash

# 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 tabelas
echo "10 link1" >> /etc/iproute2/rt_tables
echo "11 link2" >> /etc/iproute2/rt_tables
echo "30 conexao" >> /etc/iproute2/rt_tables

#Setando variaveis
export L1_DEV=eth1
export L1_IP="`ifconfig $L1_DEV | grep 'Bcast:' | cut -f2 -d: | cut -f1 -d' '`"
export L1_GW="192.168.0.100"
export L1_NET="$L1_GW/32"
echo "DEV=$L1_DEV IP=$L1_IP GW=$L1_GW NET=$L1_NET"

export L2_DEV=eth2
export L2_IP="`ifconfig $L2_DEV | grep 'Bcast:' | cut -f2 -d: | cut -f1 -d' '`"
export L2_GW="192.168.3.1"
export L2_NET="$L2_IP/26"
echo "DEV=$L2_DEV IP=$L2_IP GW=$L2_GW NET=$L2_NET"

#limpando rotas default
route del -net default gw $L2_GW
route del -net default gw $L1_GW

#Removendo deteccao de pacotes marcianos
for eee in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo 0 > $eee
done
cat /proc/sys/net/ipv4/conf/*/rp_filter

#adicionando rotas para as tabelas de roteamento
ip route add $L2_IP via $L2_GW table link1
ip route add $L1_IP via $L1_GW table link2

#adicionando regras as tabelas de roteamento
ip rule del from $L2_IP
ip rule add from $L2_IP table link1
ip rule del from $L1_IP
ip rule add from $L1_IP table link2

#adicionando rota default para as tabelas de roteamento
ip route add default via $L2_GW table link1
ip route add default via $L1_GW table link2

#adicionando routa default
ip route add default via $L1_GW

#load balancing
ip rule del fwmark 0x3
ip rule add fwmark 0x3 lookup conexao prio 3
ip route add default table conexao \
        nexthop via $L1_GW dev $L1_DEV weight 4 \
        nexthop via $L2_GW dev $L2_DEV weight 1

ip route flush cache

#Marcando pacotes
iptables -A PREROUTING -t mangle -i eth0 -d 0/0 -j MARK --set-mark 0x3