[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Multihoming Setup (w/ Apache)



Why don't I finish that though ... think I hit CTRL-ENTER by accident, 
apparently that sends the email.

On April 25, 2003 02:46 pm, Sean Abrahams wrote:

> I'm hoping someone can guide me through setting up Debian for
> Multihoming and then possibly configuring Apache to play nice with it.

Normally a linux machine has 3 routing tables, they are:

- default routing table (numerically table 253)
- main routing table (numerically table 254)
- local routing table (numerically table 255)

If you would like to see what is in each of those tables the commands
"ip route sh table [local|main|default]".

The kernel routes traffic based on rules.  These rules can be seen with the 
command "ip rule list", by default the rules are:

    0:         from all lookup local
    32766:  from all lookup main
    32767:  from all lookup default

Each packet will traverse these rules until a routing decision is made.  All 
traffic will first be checked against the local table, if a matching route is 
found then that route will be used and processing stopped (from a routing 
decision perspective), if no matching route is found in local then the next 
rule is looked at (one specifying to check the main table), and so on.  I 
might be oversimplifying but that's the general idea.
    
To properly route traffic to the Internet when you are multi-homed you will 
have to resort to advanced routing tricks (unless you have a smart router in 
front of your machine).  Advanced routing essentially means creating extra 
routing tables and using routing rules to pass packets through different 
tables as required.

I'll assume that your host has the ip addresses 172.16.0.10 and 192.168.0.10, 
both of those networks with a 255.255.255.0 netmask.  The default traffic for 
both networks will be the .254 ip.

The problem with "normal" routing is that all non-local traffic will be sent 
to the default gateway which is not always sufficient if you are multi-homed.
So, create a routing table giving the default route for each network:

    ip route add default via 192.168.0.254 table 192
    ip route add default via 172.16.0.254 table 172

The routing table numbers chosen are arbitrary and they can be specified by 
name if you create a name to number mapping in /etc/iproute2/rt_tables.

Next you must add some rules to make sure that traffic destined for the 
Internet goes out through the correct router.  Here is how I do that:

    ip rule add from 172.16.0.0/24 lookup table 172 priority 1000
    ip rule add from 192.168.0.0/24 lookup table 192 priority 1000

The priority numbers are arbitrary but must be between 0 and 32766.  One 
remaining problem is that locally destined traffic will be sent to your 
default gateways unless you add specific rules to handle local traffic.  I do 
that like this (although it could also be done with a throw route in the 172 
and 192 tables):

    ip rule add to 172.16.0.0/24 lookup table main priority 500
    ip rule add to 192.168.0.0/24 lookup table main priority 500

Now your routing rules will look like this:

    0:         from all lookup local
    500:     to 172.16.0.0/24 lookup main
    500:     to 192.168.0.0/24 lookup main
    1000:    from 172.16.0.0/24 lookup 172
    1000:    from 192.168.0.0/24 lookup 192
    32766:  from all lookup main
    32767:  from all lookup default

The last thing to do is flush your routing cache so that the changes take 
immediate effect, that is done with the command "ip route flush cache".

As for apache there's no problem.  If you connect to 172.16.0.10, then that is 
the source ip that apache will respond from and the routing rules take care 
of the rest.

With virtual hosting you can do either of these:

    <VirtualHost 172.16.0.10 192.168.0.10>
        ...
    </VirtualHost>

    <VirtualHost *>
        ...
    </VirtualHost>

> I've been unsuccessful in finding online resources.

Look for the advanced routing howto.

-- 
Fraser Campbell <fraser@wehave.net>                 http://www.wehave.net/
Brampton, Ontario, Canada                                 Debian GNU/Linux



Reply to: