#!/bin/bash

echo 1 >/proc/sys/net/ipv4/conf/all/forwarding

/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp

IP="/sbin/ip"

ip route flush all
$IP link set eth0 up
$IP addr flush dev eth0
$IP addr add 192.168.1.2/20 brd + dev eth0
$IP addr flush dev eth1
$IP addr add 192.168.16.1/28 brd + dev eth1
$IP addr flush dev eth2
$IP addr add 192.168.17.1/28 brd + dev eth2

ifconfig eth0 up
ifconfig eth1 up
ifconfig eth2 up
$IP rule del prio 50 >&/dev/null
$IP rule add prio 50 table main
$IP route del default table main >&/dev/null

# a mortadelo i filemón
#GW1=192.168.1.10
#GW2=192.168.1.13
GW1=192.168.16.2
GW2=192.168.17.2
NE1=192.168.16.0/28
NE2=192.168.17.0/28
IPE1=192.168.16.1
IPE2=192.168.17.1

# proto static
#$IP route del table 222 >&/dev/null
#$IP route add default table 222 equalize\
#	nexthop via $GW1 dev eth1 weight 1 nexthop via $GW2 dev eth2 weight 1
$IP route add default table 222 via $GW1 dev eth1

$IP rule del prio 222 >&/dev/null
$IP rule add prio 222 table 222

$IP rule del prio 202 from $NE1 >&/dev/null
$IP route del table 202 >&/dev/null
$IP route add default via $GW1 dev eth1 src $IPE1 proto static table 202
$IP route append prohibit default table 202 metric 1 proto static
$IP rule add prio 202 from $NE1 dev eth1 table 202

$IP rule del prio 201 from $NE2 >&/dev/null
$IP route del table 201 >&/dev/null
$IP route add default via $GW2 dev eth2 src $IPE2 proto static table 201
$IP route append prohibit default table 201 metric 1 proto static
$IP rule add prio 201 from $NE2 dev eth2 table 201
