Actions: | Security

AllGoodBits.org

Navigation: Home | Services | Tools | Articles | Other

Multiple Routing Tables with iproute2

Scenario

Problem

Solution

Here's what we're going to end up with:

eth0/br0
ip addr: 192.168.1.128 network: 192.168.1.0/24 gw 192.168.1.1
eth1/br1
ip addr: 10.1.0.10 network: 10.1.0.0/24 gw 10.1.0.1

Here's what we start with. It's a basic result of having configured a single interface to bridge:

#ip route show
192.168.1.0/24 dev br0
default via 192.168.1.1 dev br0

Create a custom routing table:

echo "1   myorg" >> /etc/iproute2/rt_tables

Specify a static route to the secondary gateway (this is necessary if and only if it's on the same ethernet segment):

ip route add 10.1.0.1 scope link dev br1

Specify the conditions that should use our custom table:

ip rule add from 10.1.0.0/24 table myorg

Teach our custom routing table the gateway it should use:

ip route add default via 10.1.0.1 dev br1 table myorg

Scenario 2

Create a custom routing table:

echo "1   myorg" >> /etc/iproute2/rt_tables

Specify a static route to the secondary gateway (this is necessary if and only if it's on the same ethernet segment):

ip route add 10.8.0.1 scope link dev eth1

Specify the conditions that should use our custom table:

ip rule add from 10.8.0.79 table myorg

Teach our custom routing table the gateway it should use:

ip route add default via 10.8.0.1 dev eth1 table myorg

References

Again the most important reference link for me is the Linux Advanced Routing & Traffic Control HOWTO, but also IPROUTE2 Utility Suite Howto and Linux Advanced Routing Mini HOWTO.