In case it is confusing about the "wider CIDR" in relation to the "two subnets", my point is that from the perspective of the Pi's routing, there should be two distinct subnets, one on each interface. That's done with the dhcpcd.conf
you have using 192.168.4.1/24
and 192.168.5.1/24
. I presume you understand how CIDRs work (if not you need to), but these are both 256 addresses wide, with no overlap. Hence if you look at ip route
you should see one for each.
But if possible (this depends on whether DCHP allows for this, which it would be a bit silly if it didn't -- you'll have to figure out how to configure dnsmasq to do it), what you want clients on both interfaces to believe in is:
192.168.0.0/16
This CIDR is twice as wide in terms of bits (32 - 16 = 16 vs. 32 - 24 = 8), and 256 times wider in terms of addresses (so, 65536). It includes both 192.168.4.0/24 and 192.168.5.0/24.
This way, the clients will configure their own routing to use the link to the for that entire wider range. Eg., 192.168.4.10 will send packets to the Pi for 192.168.5.42, and because of the forwarding rules, those will passed straight through as is to the other interface.2
The potential problem with this is clients might not be able to correctly connect with others on their own subnet. If that matters, some more complex iptables rules will be needed.
- What would make it apply is if the CIDR used by the DHCP server were sufficient to include both subnets, eg. 192.168.0.0/16.
What would make it apply is if the CIDR used by the DHCP server were sufficient to include both subnets, eg. 192.168.0.0/16.
You don't have to use
/16
; 15 bits will cover up to 192.168.7.255 so you could use/27
.