Posts Tagged ‘bash’

Linux: Routing for multiple uplinks/providers

Thursday, July 16th, 2009

I described my problem here: http://www.linuxquestions.org/questions/linux-networking-3/problem-with-routing-for-multiple-uplinksproviders-on-rh9-2.4.36.2-739775/
As of this writing, it’s not yet solved.
However, I wanted to post a script that does exactly what’s in the tutorial http://lartc.org/howto/lartc.rpdb.multiple-links.html
that I use since I hate keep adding them by hand:
you need to edit it and add your info, obviously.

#!/bin/sh

# config stuff
P1_NET=
IF1=
P1=
IP1=
T1=T1

P2_NET=
IF2=
P2=
IP2=
T2=T2

P0_NET=
IF0=
P0=
IP0=
# actual script

if [ "$1" == "del" ]
then
CMD=del
else
CMD=add
fi

/sbin/ip route $CMD $P1_NET dev $IF1 src $IP1 table $T1
/sbin/ip route $CMD default via $P1 table $T1
/sbin/ip route $CMD $P2_NET dev $IF2 src $IP2 table $T2
/sbin/ip route $CMD default via $P2 table $T2

/sbin/ip route $CMD $P1_NET dev $IF1 src $IP1
/sbin/ip route $CMD $P2_NET dev $IF2 src $IP2

/sbin/ip route $CMD default via $P1

/sbin/ip rule $CMD from $IP1 table $T1
/sbin/ip rule $CMD from $IP2 table $T2

uselocal=true
if [ $uselocal == true ]
then
/sbin/ip route $CMD $P0_NET dev $IF0 table $T1
/sbin/ip route $CMD $P2_NET dev $IF2 table $T1
/sbin/ip route $CMD 127.0.0.0/8 dev lo table $T1
/sbin/ip route $CMD $P0_NET dev $IF0 table $T2
/sbin/ip route $CMD $P1_NET dev $IF1 table $T2
/sbin/ip route $CMD 127.0.0.0/8 dev lo table $T2
fi

Related posts