#!/bin/bash ip="/usr/sbin/ip" IF1="eth0" #Interface connecting to provider 1 IF2="eth1.4" #Interface connecting to provider 2 IP1="213.40.81.180" #IP from provider 1 IP2="192.168.15.2" #IP from provider 2 P1="213.40.81.1" #GW of provider 1 P2="192.168.15.1" #GW of provider 2 P1_NET="213.40.81.0/24" P2_NET="192.168.15.0/24" localnets="127.0.0.0/8 10.0.0.0/8 192.168.0.0/16 83.229.68.236/30 $P1_NET $P2_NET " #setup the routing tables $ip route add $P1_NET dev $IF1 src $IP1 table T1 #think this is not needed $ip route add default via $P1 table d3 $ip route add $P2_NET dev $IF2 src $IP2 table T2 #think this is not needed $ip route add default via $P2 table btk #automagically exist #$ip route add $P1_NET dev $IF1 src $IP1 #$ip route add $P2_NET dev $IF2 src $IP2 $ip route add default via $P2 #prefered default gateway #Answers shuld be sent through the same interface, # where requests came in from. $ip rule add from $IP1 lookup T1 $ip rule add from $IP2 table T2 #here is routing for individual clients #In this example 10.10.240.0/22 is routed through provider 1 #and 10.0.0.0/8 through provider 2 $ip rule add from 10.0.0.0/8 table T2 $ip rule add from 83.229.68.236/30 table T1 $ip rule add from 10.10.240.0/22 table T1 #make sure local networks are reached as normal for i in $localnets; do $ip rule add to $i table main done