Linux Multiple Interface
Linux Multiple Interface
Linux Multiple Interface
Better than load balancer Compare true broadband bonding to other load balancers. www.mushroomnetworks.com/bonding
BAS Gateway Leading gateway linking BACnet LonWorks, Modbus, Metasys & more www.FieldServer.com
AMHS Support Services ATS Message Handling System: AMHS Book - Test Support - Training www.ac-b.de
________
+------------+ /
| | |
+-------------+ Provider 1 +-------
__ | | | /
___/ \_ +------+-------+ +------------+ |
_/ \__ | if1 | /
/ \ | | |
| Local network -----+ Linux router | | Internet
\_ __/ | | |
\__ __/ | if2 | \
\___/ +------+-------+ +------------+ |
| | | \
+-------------+ Provider 2 +-------
| | |
+------------+ \________
Let us first set some symbolical names. Let $IF1 be the name of the first interface (if1 in the picture above) and
$IF2 the name of the second interface. Then let $IP1 be the IP address associated with $IF1 and $IP2 the IP
address associated with $IF2. Next, let $P1 be the IP address of the gateway at Provider 1, and $P2 the IP address
of the gateway at provider 2. Finally, let $P1_NET be the IP network $P1 is in, and $P2_NET the IP network $P2
is in.
One creates two additional routing tables, say T1 and T2. These are added in /etc/iproute2/rt_tables. Then you set
up routing in these tables as follows:
Nothing 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.
Next you set up the main routing table. It is a good idea to route things to the direct neighbour through the interface
connected to that neighbour. Note the `src' arguments, they make sure the right outgoing IP address is chosen.
http://lartc.org/howto/lartc.rpdb.multiple-links.html 4/15/2011
Routing for multiple uplinks/providers Page 2 of 3
Next, 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:
This set of commands makes sure all answers to traffic coming in on a particular interface get answered from that
interface.
Warning Reader Rod Roark notes: 'If $P0_NET is the local network and $IF0 is its interface, the following
additional entries are desirable:
'
Now, this is just the very basic setup. It will work for all processes running on the router itself, and for the local
network, if it is masqueraded. If it is not, then you either have IP space from both providers or you are going to want
to masquerade to one of the two providers. In both cases you will want to add rules selecting which provider to
route out from based on the IP address of the machine in the local network.
Instead of choosing one of the two providers as your default route, you now set up the default route to be a
multipath route. In the default kernel this will balance routes over the two providers. It is done as follows (once
more building on the example in the section on split-access):
ip route add default scope global nexthop via $P1 dev $IF1 weight 1 \
nexthop via $P2 dev $IF2 weight 1
This will balance the routes over both providers. The weight parameters can be tweaked to favor one provider over
the other.
Note that balancing will not be perfect, as it is route based, and routes are cached. This means that routes to often-
used sites will always be over the same provider.
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.
http://lartc.org/howto/lartc.rpdb.multiple-links.html 4/15/2011
Routing for multiple uplinks/providers Page 3 of 3
http://lartc.org/howto/lartc.rpdb.multiple-links.html 4/15/2011