How to route lan trafic over VPN
The solution is actually a bit more straitforward.
Ignore the iptables
commands on machine A
for now as that is about hiding your subnet 192.168.2.0/24
behind a NAT.
Instead focus on what is actually going on when you do a ping command.
When you send a ping to a remote ip you actually need to inform both machine A
and machine B
how to get the respective networks 192.168.0.0/24
and 192.168.2.0/24
.
You got the first part right about telling machine B
that in order to ping anything on 192.168.2.0/24
it has to go through 25.61.150.71
.
That is what you did in the command:
machineB> sudo ip route add 192.168.2.0/24 via 25.61.150.71
This is possible since machine A
and machine B
is on the same subnet provided by Hamachi.
But any ping command also needs to send a reply back, so how does the machine A
know where the network 192.168.0.0/24
is located?
You can tell machine A
that the subnet 192.168.0.0/24
is located behind 25.72.151.72
.
This leads the the following command:
machineA> sudo ip route add 192.168.0.0/24 via 25.72.151.72
However we are not quite out of the woods yet, since even though machine A
and machine B
knows where to send traffic to any host belonging to either net we still have the challange of how does any other host belonging to the 192.168.0.0/24
know how to contact 192.168.2.0/24
?
If machine A
and machine B
is not the default gateway for their networks, then we need to add a static route to the default gateway on either net.
For machine A
's default router we need to tell that 192.168.0.0/24
is reachable through 192.168.2.160
.
Similar we need to tell machine B
's default router that 192.168.2.0/24
is reachable through 192.168.0.103
.
After all this is done you should be able to ping from any host belonging to either net to any host belonging to the other net.