Force routing between three hosts

Hi,
I'm having problem trying to create the following scenario: VM1 <--> VM2 <--> VM3

where VM1, VM2 and VM3 are virtual machines and VM1 and VM3 have to pass trough VM2 to "talk" each other.

The best solution should be change the default gateway of VM1 and VM3 by pointing it to VM2 IP address.

For this reason, I've tried to add a new default gateway (route add default gw <VM2_IP>) and then I tried to delete the old default gateway but it is not working.

I've also tried to add a new route for VM3 in VM1:
route add -host <IP_VM3> gw <IP_VM2>
but in this case the VM3 is unreachable from VM1.

How can I do it?
Is there any specific procedure since they are VMs and not physical machine?

Thanks,
Massimo

Hi

You need use iptables to DNAT all outgoing traffic

HI,
thanks for your answer.
I'm not sure if I get your hint.

Did you suggest me to use DNAT on VM1 and VM3?

In particular, you suggest me to do this on VM1:
iptables -t nat -A PREROUTING -i eth0 -j DNAT --to <IP_VM2>

Is it right?

Just to be sure, what I want is to send a packet from VM1 to VM3, but this packet
have to pass through VM2.

Should I do something in VM2,like enable IP forwarding?

Sorry for these (maybe) newbie question.

Thanks,
M

posted a wrong type of answer, please delete this message

Any idea about this?
M