#!/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" #setup the routing tables $ip route add $P1_NET dev $IF1 src $IP1 table T1 $ip route add default via $P1 table d3 $ip route add $P2_NET dev $IF2 src $IP2 table T2 $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 #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 $ip route add default via $P2 table default #prefered default gateway #Prefer the main table, but there sould be no default route $ip route del default table main &> /dev/null $ip rule del from all lookup main $ip rule add from all lookup main