Friday, January 29, 2021

Linux IP Routing Problem

LONG POST ALERT**

Hey, so I am new to computer networking and trying to wrap my head around linux IP routing but no amount of googling or trial and error is working.

Apologies in advance if my post is lacking any detail, I am finding my thoughts very muddled right now but give me a nudge and I will update :).

I have 4 VM's (Ubuntu 20.04 Servers), each has 2 network adapters (NA) and static IP's as follows:

Machine 1:

NA1 - VMNet2 - 192.168.1.1

NA2 - VMNet3 - 192.168.2.1

Machine2:

NA1 - VMNet3 - 192.168.2.2

NA2 - VMNet4 - 192.168.3.1

Machine3:

NA1 - VMNet4 - 192.168.3.2

NA2 - VMNet5 - 192.168.4.1

Machine4:

NA1 - VMNet5 - 192.168.4.2

NA2 - VMNet2 - 192.168.1.2

The aim is to be able to ping Machine 3 from Machine 1, with all traffic only being sent by Network Adapter2, and all traffic only being received by Network Adapter 1.

My routing tables on each machine are as follows (will just shot machine 1, the same applies on the other machines except the IP address/ranges adjust accordingly):

- default via 192.168.2.1 dev ens38

- 192.168.1.0/24 dev ens33 proto kernel scope link src 192.168.1.1

- 192.168.2.0/24 dev ens38 proto kernel scope link src 192.168.2.1

If my understanding is correct (please correct me if I'm wrong), the first rule is the default rule that will apply if the other rules don't i.e. that any traffic unaccounted for should be sent to the default gateway via 192.168.2.1 on ens38 (network adapter 2).

The second rule is that any traffic from 192.168.1.1 should go to the 192.168.1.0/24 range if applicable via ens33 (network adapter 1). The same for rule 3 but change the range and network adapter accordingly.

I've enabled IP forwarding on the 4 machines using "sysctl -w net.ipv4.ip_forward=1"

I tried the following rules (my logic will go in the brackets after the command):

- Machine 2 = ip route add 192.168.3.2/24 via 192.168.3.1 dev ens38 (My logic here being that the ping would go out from the 2.1 address on machine 1, to the 2.2 address on machine 2, get forwarded to the 3.1 address on machine 2 and go from there to the 3.2 address on machine 3 as they are on the same local network. Didn't work)

- Machine 1 - ip route add 192.168.3.0/24 via 192.168.2.1 dev ens38 (my logic here being to force any traffic intended for the 192.168.3.0/24 range to go through the 2.1 address on ens38, then realised that the default gateway already deals with this so this rule did nothing new)

- then I wondered why the default gateway rule on Machine 2 "default via 192.168.3.1 dev ens38 proto static" on machine 2 didn't pick up the ping request and force it out via the 3.1 address.

From here, madness ensued and I can't even think of logic for anything i tried after this. I am hoping someone can make sense of the mess that is now my brain and help me out



No comments:

Post a Comment