Routing for multiple uplinks/providers

Source: Internet
Author: User
Http://lartc.org/howto/lartc.rpdb.multiple-links.html

4.2. Routing for multiple uplinks/providers

A common configuration is the following, in which there are two providers that connect a local network (or even a single machine) to the big internet.

                                                                 ________
+------------+ /
| | |
+-------------+ Provider 1 +-------
__ | | | /
___/ \_ +------+-------+ +------------+ |
_/ \__ | if1 | /
/ \ | | |
| Local network -----+ Linux router | | Internet
\_ __/ | | |
\__ __/ | if2 | \
\___/ +------+-------+ +------------+ |
| | | \
+-------------+ Provider 2 +-------
| | |
+------------+ \________

There are usually two questions given this setup.

4.2.1. Split access

The first is how to route answers to packets coming in over a participant provider, say provider 1, back out again over that same provider.

Let us first set some symbolical names. Let$ If1Be the name of the first interface (if1 in the picture above) and$ If2The name of the second interface. Then let$ IP1Be the IP address associated$ If1And$ Ip2The IP address associated$ If2. Next, let$ P1Be the IP address of the gateway at provider 1, and$ P2The IP address of the gateway at provider 2. Finally, let$ P1_netBe the IP Network$ P1Is in, and$ P2_netThe IP Network$ P2Is in.

One creates two additional routing tables, sayT1AndT2. These are added in/etc/iproute2/rt_tables. Then you set up routing in these tables as follows:

  ip route add $P1_NET dev $IF1 src $IP1 table T1
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

Nothing spectacular, just build a route to the gateway and build a default route via that gateway, As you wocould 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 has des the gateway, as specified above.

Next you set up the main routing table. it is a good idea to route things to the direct neighbor through the interface connected to that neighbor. note the 'src' arguments, they make sure the right outgoing IP address is chosen.

    ip route add $P1_NET dev $IF1 src $IP1
ip route add $P2_NET dev $IF2 src $IP2

Then, your preference for default route:

    ip route add default via $P1

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:

    ip rule add from $IP1 table T1
ip rule add from $IP2 table T2

This set of commands makes sure all answers to traffic coming in on a participant interface get answered from that interface.

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
ip route add $P2_NET dev $IF2 table T1
ip route add 127.0.0.0/8 dev lo table T1
ip route add $P0_NET dev $IF0 table T2
ip route add $P1_NET dev $IF1 table T2
ip route add 127.0.0.0/8 dev lo table T2

'

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.

4.2.2. Load Balancing

The second question is how to balance traffic going out over the two providers. This is actually not hard if you already have set up split access as abve.

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.WeightParameters 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.