# Multiple default gateways [Solved sort of]

## gerdesj

I have two ADSL links to the Internet connected to my LAN and I would like to be able to use both of them simultaneously.

I have read LARTC's guide and they give a good example using multiple NICs but I would like to use one NIC only, in effect using both as a default gateway.

Is this possible ?

I have read an awfull lot of stuff about multilink and fwmarking packets but am now a bit confused.  If I have to resort to two NICs then so be it but I hope there is a way of round robining connections or something.Last edited by gerdesj on Wed Nov 02, 2005 12:00 am; edited 1 time in total

----------

## adaptr

 *gerdesj wrote:*   

> I have two ADSL links to the Internet connected to my LAN and I would like to be able to use both of them simultaneously.

 

Can't be done - not in the way you probably think.

 *gerdesj wrote:*   

> I have read LARTC's guide and they give a good example using multiple NICs but I would like to use one NIC only, in effect using both as a default gateway.

 

Positively can't be done - how would you connect two modems to a single NIC ?

 *gerdesj wrote:*   

> Is this possible ?

 

Only if your ISP supports line bonding, otherwise: not a chance.

 *gerdesj wrote:*   

> I have read an awfull lot of stuff about multilink and fwmarking packets but am now a bit confused.  If I have to resort to two NICs then so be it but I hope there is a way of round robining connections or something.

 

That's just the point - you cannot round-robin TCP connections since you have no control over where the return packets will end up.

It's a two-way protocol, and you need to configure both ends.

If you connect each modem to a separate NIC then you can split up certain kinds of traffic - say, HTPP to one modem and FTP to another - but you cannot combine the two connections on only one side.

----------

## gerdesj

I haven't really stated the goal of this exercise properly.  The point is really to provide fault tolerance of some sort. 

One "modem" is a Draytek router and the other is a Gentoo box with an ADSL PCI card in it.  The Draytek is the default gateway for all devices on the LAN, the Gentoo box has its own connection for dial up (VPN) and several other things.  We are unable to get over 512Kb connections here so two lines.

I would like to be able to get my laptop (Gentoo) and all the other devices on this LAN to use the Draytek but fail over to the Gentoo box in the event of problems.  Windows seems to have multiple default gateway support and NetWare has as well but I am stumped for Linux.

The long term goal is to have both lines in the Gentoo box and use MLPPP but that is a while away (two different ISPs, need to move one of the lines over to the other).

I've looked at ifplugd even but that looks at plugin/out events.  

 *adaptr wrote:*   

>  *gerdesj wrote:*   I have read LARTC's guide and they give a good example using multiple NICs but I would like to use one NIC only, in effect using both as a default gateway. 
> 
> Positively can't be done - how would you connect two modems to a single NIC ?

 

----------

## adaptr

Why a long term goal ?

Stick the draytek modem in the Gentoo box and do all routing from there - failover is easy in that case.

You do realise that failover does not mean having both lines up simultaneously, right ?

----------

## gerdesj

 *adaptr wrote:*   

> Why a long term goal ?
> 
> Stick the draytek modem in the Gentoo box and do all routing from there - failover is easy in that case.
> 
> You do realise that failover does not mean having both lines up simultaneously, right ?

 

The Draytek is a router not a modem (although it has one built in).  Failover only is the last resort.  Ideally I'd like to be able to use both connections simultaneously, this would accommodate "failover" given that connections already in progress on the failing line would be dropped.  

I can see how to use one or the other link depending on destination but that implies a potentially large routing table.

Perhaps a rephrase of the question might help:

From a PC with a single NIC and two equally good routes to another network, can the routing table be manipulated to allow selection of either route?  The route selected should be random or round robin but if a route is unavailable then the other should be used.

If the answer is no, then I'll just have to look into the LARTC method with multiple interfaces and using multiple tables.

----------

## adaptr

 *gerdesj wrote:*   

> The Draytek is a router not a modem (although it has one built in).

 

You said:

 *Quote:*   

> One "modem" is a Draytek router 

 

so that's what I am going on.

 *gerdesj wrote:*   

>   Failover only is the last resort.  Ideally I'd like to be able to use both connections simultaneously, this would accommodate "failover" given that connections already in progress on the failing line would be dropped.  

 

...yes. Except that the two are really not the same.

As in: you cannot implement them the same way.

If you implement a failover then you have to put some mechanism in place to accomplish the switch.

But if you set them up to loadbalance then when one fails you will have a crippled loadbalancer - which may or may not perform correctly.

This all depends on how you set it up.

 *gerdesj wrote:*   

> I can see how to use one or the other link depending on destination but that implies a potentially large routing table.

 

Not at all, and not what I'd recommend.

Split traffic up by protocol, this is easily managed with iptables.

 *gerdesj wrote:*   

> Perhaps a rephrase of the question might help:
> 
> From a PC with a single NIC and two equally good routes to another network, can the routing table be manipulated to allow selection of either route?  The route selected should be random or round robin but if a route is unavailable then the other should be used.

 

Of course - use a routing protocol.

The only snag is exactly the same one I mentioned earlier - you cannot accomplish this on your own.

The ISP on the other side of the lines has to provide this, and set it up accordingly.

If you can convince them to set up a RIP router between you and them, one with just two routes to all possible networks, then that should do it.

The overhead is low, and maintenance is zero.

 *gerdesj wrote:*   

> If the answer is no, then I'll just have to look into the LARTC method with multiple interfaces and using multiple tables.

 

Again, I'm sorry to burst your hopes there, but unless the ISP cooperates, there is not much you can do.

----------

## bschrock

Yeah!

Use a hub...

Once you have the two ADSL modems ethernets plugged into a hub and your PC's sinlge ethernet card plugged in configure...

```

ifcfonfig eth0:1 <ip address> netmask <netmask> up

ifconfig eth0:2 <ip address> netmask <netmask> up

```

Then do...

```

ip route add default scope global nexthop via $P1 dev $IF1 weight 1 \

       nexthop via $P2 dev $IF2 weight 1

```

And if you want to get even more advanced look at this site...

http://lartc.org/howto/lartc.rpdb.multiple-links.html

----------

## bigfunkymo

I've heard of load balancing where you use CONNMARK or something to make all future packets that are part of a TCP stream to be routed via the same interface.

----------

## gerdesj

Thank you all very much for your comments.  Much appreciated.

bschrock and bigfunkymo between you could well have hit the nail on the head.  I hadn't thought of aliasing to split eth{x} into two+ interfaces and fwmark'ing packets seems a good idea to ensure that outgoing and incomming packets stay on the same interface for a given stream.

Let's see what happens.  I'll post back in a few days when I've given it a whizz ...

Cheers all and thanks for your time.

----------

## adaptr

Marking and splitting the traffic will work only for any traffic that originates from your side of the uplink - it fails as soon as someone from the outside tries to connect to one of your IPs.

But by all means give it a try - maybe you will hit a solution that you can work with.

----------

## bschrock

Yes,

These solutions only work for outbound traffic... btw there is also a patch to the kernel that does dead gateway detection they can be found by visiting the link I posted earlier.

----------

## gerdesj

 *bschrock wrote:*   

> Yes,
> 
> These solutions only work for outbound traffic... btw there is also a patch to the kernel that does dead gateway detection they can be found by visiting the link I posted earlier.

 

Just in case someone else (guaranteed) hits this see:

http://mailman.ds9a.nl/pipermail/lartc/2003q4/010372.html

http://www.ssi.bg/~ja/

I use a combination of the script in the first link with:

# LINK 1

EXTIF1=wan0

EXTIP1=`$IP addr show $EXTIF1 | grep -m 1 inet | awk '{print $2}' | cut --delimiter="/" -f1`

EXTM1=32

EXTGW1=`$IP addr show $EXTIF1 | grep -m 1 inet | awk '{print $4}' | cut --delimiter="/" -f1`

# LINK 2

EXTIF2=wan1

EXTIP2=`${IP} addr show $EXTIF2 | grep -m 1 inet | awk '{print $2}' | cut --delimiter="/" -f1`

EXTM2=32

EXTGW2=`$IP addr show $EXTIF2 | grep -m 1 inet | awk '{print $4}' | cut --delimiter="/" -f1`

and the ping bit put in a cron job.  This is all a bit of a mess (I also use fwbuilder because I have around 15 networks and climbing).  Once I get to the bottom of the whole thing (and that includes getting PPPoA sorted into baselayout, I'll be posting a full HOWTO.

... and whilst you are at it read this:

http://www.policyrouting.org/PolicyRoutingBook/ONLINE/TOC.html

So far it works ...

Of course MultiLink PPP is the real way to go.  In the UK see Nildram as an ISP.  With them you can effectively bond ADSL links together.  There may be others but I know that Plus Net and Eclipse can't (can't remember Demon's answer).  The best bit with MLPPP is you get n times the uplink speed.  Ths is great for those of us needing to avoid the SDSL "tax" eg wedge 4 links together and you have 1Mb out (with 8Mb down).  Nildram also have an enlightened policy towards reverse DNS entries (try running a mail system without it).  

Incidently, I'm not a Nildram employee (I'm using Plus at home at the moment)

Just to recap:

Patch the kernel with 

http://www.ssi.bg/~ja/#routes

download the relavent one into /usr/src , cd there and #patch -p0 < name_of_patch.  Rebuild the kernel eg #genkernel --no-clean --no-mrproper --menuconfig all

Then use the script to get the routing sorted.

As I said earlier, I'll get a full HOWTO together on the Wiki when I've got it all sorted and I have time.

Cheers

Jon

----------

