Routing for multiple uplinks/providers
http://lartc.org/howto/lartc.rpdb.multiple-links.html
4.2. Routing for multiple uplinks/providers
________
+------------+ /
| | |
+-------------+ Provider 1 +-------
__ | | | /
___/ \_ +------+-------+ +------------+ |
_/ \__ | if1 | /
/ \ | | |
| Local network -----+ Linux router | | Internet
\_ __/ | | |
\__ __/ | if2 | \
\___/ +------+-------+ +------------+ |
| | | \
+-------------+ Provider 2 +-------
| | |
+------------+ \________
There are usually two questions given this setup.
4.2.1. Split access
ip route add $P1_NET dev $IF1 src $IP1 table T1Nothing spectacular, just build a route to the gateway and build a default route via that gateway, as you would do in the case of a single upstream provider, but put the routes in a separate table per provider. Note that the network route suffices, as it tells you how to find any host in that network, which includes the gateway, as specified above.
ip route add default via $P1 table T1
ip route add $P2_NET dev $IF2 src $IP2 table T2
ip route add default via $P2 table T2
ip route add $P1_NET dev $IF1 src $IP1Then, your preference for default route:
ip route add $P2_NET dev $IF2 src $IP2
ip route add default via $P1Next, you set up the routing rules. These actually choose what routing table to route with. You want to make sure that you route out a given interface if you already have the corresponding source address:
ip rule add from $IP1 table T1This set of commands makes sure all answers to traffic coming in on a particular interface get answered from that interface.
ip rule add from $IP2 table T2
![]() | Reader Rod Roark notes: 'If $P0_NET is the local network and $IF0 is its interface, the following additional entries are desirable: ip route add $P0_NET dev $IF0 table T1' |
4.2.2. Load balancing
ip route add default scope global nexthop via $P1 dev $IF1 weight 1 \This will balance the routes over both providers. The weight parameters can be tweaked to favor one provider over the other.
nexthop via $P2 dev $IF2 weight 1
Furthermore, if you really want to do this, you probably also want to look at Julian Anastasov's patches at http://www.ssi.bg/~ja/#routes , Julian's route patch page. They will make things nicer to work with.