Home

Simple split brain networking with linux (and optional Jinja)

A remarkably common scenario for a network-centric Linux box is needing to reach <-> with other networks needing a default route gateway depending on which interface (IP address) the request came in on.

Say if I have ip_1: 139.178.82.115/31 and ip_2: 147.75.35.130/28, and if a request comes in on ip_1, we need to return it to the default gateway gw_1: 139.178.82.114, and if a request comes in on ip_2, we need to return it to the default gateway of gw_2: 147.75.35.128?

Especially in virtual networking heavy environments, the ability to split traffic based on origin to a different default gateway can simplify some awfully cumbersome challenges.

Linux makes this easy with quick access to a poor person's VRF, the linux routing table (bonus! With bonds and VLANs!):

Put all together:

echo 200 bond0.2335 >> /etc/iproute2/rt_tables
ip rule add from 147.75.35.146 table bond0.2335 priority 900
ip route add default via 147.75.35.145 dev bond0.2335 table bond0.2335
ip route add 147.75.35.144/28 dev bond0.2335 proto static scope link src 147.75.35.146 table bond0.2335

This explanation is obviously simplified but it isn't much more complicated than it looks.

Automation

Templating this stuff ain't hard. Examples from a recent project with OpenShift.

Even though it's only specific to that project, it's an example of how one can use things like Ansible's ansible.utils.nthhost filter to make a tedious task... slightly less tedious.

This was to be able to host assets on both the Equinix Metal Layer-3 network as well as a OpenShift cluster specific network, where the Layer-3 network was a sort of infrastructure control-plane while the VLAN'ed network was the OpenShift cluster control-plane. Worked like a charm.

#jinja #linux #networking