You are here: Home / Software / source based routing

source based routing

or how to have multiple default gateways

Imagine a multi homed system. That is a system with more then one network interface, each interface connected to a different ip network.

On a normal system you will have one subnet on each interface and one default route:

           +--- router0 ( --- eth0 (
outside ---+
           +--- router1 ( --- eth1 (
root@host# route -n
Kernel IP routing table
Destination   Gateway       Genmask         Flags Metric Ref    Use Iface   U     0      0        0 eth0   U     0      0        0 eth1         UG    0      0        0 eth0

If a Client ( connects to a service on everything is fine. Packet comes from the outside, goes to router0 (decided by some router not under your control), hits eth0. Now how to answer? As we have no special route to we will choose the default route and go out eth0, to router0 and from there outside.

Now what happens if we connect to Packet comes from outside, goes to router1, hits eth1. Answer goes? Right we don’t know how to talk to so we choose the default route. Packet goes out eth0, router0, outside.

Why is this bad?

You can have inbound traffic in the amount of bandwith-eth0 + bandwith-eth1. But Outbound you will only send via eth0, so there is a missmatch. Also various tcp optimizations (congestion, windows, etc) won’t work to well if using different interfaces.

What do you want?

Two default gateways. If i send traffic as i want to use eth1, otherwise eth0. Iproute2 to the rescue!

ip route add default via eth1 table 100
ip rule add from table 100

If i send a package from, then look into table 100 (choose any number 2-252). If you find routing information there use them.

And Table 100 says, send package out using eth1 to (router1).

Whats next?

Read the documentation of iproute2!