Debian multiple network interface multiple networks

debiangatewayiptablesnetworking

I have a virtual environment with 3 virtual machines on one host. One of my virtual machines has 2 network interface.

I need the virtual machine with two interfaces to connect to two different networks.

HERE is the topology
enter image description here

My host host has an

ip 192.168.3.29
netmask 255.255.255.0
gateway 192.168.3.1

The 3 virtual machines have the ip addresses

ip 192.168.3.30
netmask 255.255.255.0
gateway 192.168.3.1

ip 192.168.3.31
netmask 255.255.255.0
gateway 192.168.3.1

ip 192.168.3.32
netmask 255.255.255.0
gateway 192.168.3.1

now i added the following setup to the virtual machine to allow it to communicate to another network.
address 10.10.0.10
netmask 255.255.255.0

I added the line below to the file /etc/iproute2/rt_tables

1 rt2

I then run the following commands.

 ip route add 10.10.0.99/32 dev eth1 src 10.10.0.10 table rt2

 ip route add default via 10.10.0.1 dev eth1 table rt2

 ip rule add from 10.10.0.99/32 table rt2

 ip rule add to 10.10.0.99/32 table rt2

The ip I am trying to reach is 10.10.0.99 and I want only that one ip to be accessed via this route.

For some reason when i try ping the ip after the above configuration i get destination unreachable.

I can reach the server 10.10.0.99 without the above configuration going through the gateway
192.168.3.1 however there is an unnecessary number of nodes between my node and the other node which sometimes causes trouble.

Is there something wrong with my steps?

I followed the steps here

I found another similar question here

Which seems to suggest i am heading in the correct direction.

Best Answer

If your VM 1 has an IP in the network 10.10.0.0/24 then there's no need for any route to communicate with 10.10.0.99, since both hosts are in the same network.

You must ensure that the host with IP 10.10.0.99 is in the same switching domain and has a 24 bit subnet mask, i.e. 255.255.255.0.

If it's not the case please provide more info about the switching config and the IP configuration of host 10.10.0.99.