Tech/Many NICs in the same subnet

From ~esantoro
Revision as of 07:55, 9 September 2024 by Esantoro (talk | contribs) (→‎Links and references)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

I recently had the chance to work on a proof of concept at work and faced an interesting challenge: what does it take to be able to use more than one network interface connected to the same subnet? One might expect that once you've got the ip addresses from your local dhcp server all is good and you can start sending and receiving traffic. I've learned that's not the case.

In this article I want to take notes about what's necessary for such configuration to work. I haven't fully understood (yet) all the pieces involved so his page will end up also being a tracker for my learnings

Charts

scenario

Quick and dirty notes

Let's say our subnet is has address 10.55.0.0/18 and our nics these addresses:

  • eth0: 10.55.36.33
  • eth1: 10.55.8.255
  • eth2: 10.55.38.187

Then the necessary commands would be:

# ==================================================================
# Block 1: tables creation

echo "10 eth0" >> /etc/iproute2/rt_tables
echo "11 eth1" >> /etc/iproute2/rt_tables
echo "12 eth2" >> /etc/iproute2/rt_tables

# ==================================================================
# Block 2: Add rules to tables

ip route add 10.55.0.0/18 dev eth0 src 10.55.36.33 table eth0
ip route add default via 10.55.0.1 dev eth0 table eth0

ip route add 10.55.0.0/18 dev eth1 src 10.55.8.255 table eth1
ip route add default via 10.55.0.1 dev eth1 table eth1

ip route add 10.55.0.0/18 dev eth2 src 10.55.38.187 table eth2
ip route add default via 10.55.0.1 dev eth2 table eth2

# ==================================================================
# Block 3: bind ip addresses to tables

ip rule add from 10.55.36.33/32 table eth0
ip rule add to 10.55.36.33/32 table eth0

ip rule add from 10.55.8.255/32 table eth1
ip rule add to 10.55.8.255/32 table eth1

ip rule add from 10.55.38.187/32 table eth2
ip rule add to 10.55.38.187/32 table eth2

Quick and dirty explanation

The block 1 creates three tables. Tables are sorted and consulted by (ascending, if I understood correctly?) order of priority. The priorities here are the 10, 11 and 12 numbers. Tables with low numbers comes first, tables with high priority numbers come later.

To give an idea, the default would be something like this:

manu@astrolabio:~$ ip rule show
0:	from all lookup local
32766:	from all lookup main
32767:	from all lookup default

So adding tables with priorities 10/11/12 would mean that such tables are consulted after the local table and before the main and default tables.

Then we move to adding rules to tables (block 2)

(to be continued)

Links and references