I have setup three Ubuntu VMs in vmware. These are connected as:
Now I want to use UBUNTU2 as router, so that when I run these commands in UBUNTU1, I get response from UBUNTU3, commands:
ping 192.168.4.103 -I eth1
ping 192.168.4.103 -I eth2
ping 192.168.4.103 -I eth3
And I get response in UBUNTU3 from UBUNTU1 for commands:
ping 192.168.1.101
ping 192.168.2.101
ping 192.168.3.101
Please help me with this.
I have routes like this:
Please ignore eth0 interface. It is connected to all VMs.
UBUNTU1:
root@ubuntu:/home# ip route show
default via 192.168.8.2 dev eth0
169.254.0.0/16 dev eth2 scope link metric 1000
192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.101
192.168.2.0/24 dev eth2 proto kernel scope link src 192.168.2.101
192.168.3.0/24 dev eth3 proto kernel scope link src 192.168.3.101
192.168.8.0/24 dev eth0 proto kernel scope link src 192.168.8.101
root@ubuntu:/home#
UBUNTU2:
root@ubuntu:/home# ip route show
default via 192.168.8.2 dev eth0 metric 100
169.254.0.0/16 dev eth3 scope link metric 1000
192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.102
192.168.2.0/24 dev eth2 proto kernel scope link src 192.168.2.102
192.168.3.0/24 dev eth3 proto kernel scope link src 192.168.3.102
192.168.4.0/24 dev eth4 proto kernel scope link src 192.168.4.102
192.168.8.0/24 dev eth0 proto kernel scope link src 192.168.8.102
root@ubuntu:/home#
UBUNTU3:
root@ubuntu:/home# ip route show
default via 192.168.8.2 dev eth0 metric 100
169.254.0.0/16 dev eth1 scope link metric 1000
192.168.4.0/24 dev eth1 proto kernel scope link src 192.168.4.103
192.168.8.0/24 dev eth0 proto kernel scope link src 192.168.8.103
root@ubuntu:/home#
EDIT1
I have enabled IP forwarding in UBUNTU2 with command:
echo 1 > /proc/sys/net/ipv4/ip_forward
And then I added these routes to UBUNTU3:
ip route add 192.168.1.0/24 scope global via 192.168.4.102 dev eth1
ip route add 192.168.2.0/24 scope global via 192.168.4.102 dev eth1
ip route add 192.168.3.0/24 scope global via 192.168.4.102 dev eth1
And I added these routes to UBUNTU1:
ip route add 192.168.4.0/24 scope global via 192.168.1.102 dev eth1
At this moment, I was able to ping UBUNTU3 from UBUNTU1 as:
ping 192.168.4.103 -I eth1
And, I was able to ping UBUNTU1 from UBUNTU3 as:
ping 192.168.1.101
But then I tried to add second route in UBUNTU1 as:
ip route add 192.168.4.0/24 scope global via 192.168.2.102 dev eth2
and command failed with route exist error.
How can I route to same other network (192.168.4.0/24) from different interfaces in machine.
EDIT2:
I added rule based routing in UBUNTU1 as:
1) Created additional table names in /etc/iproute2/rt_tables
so now file contains :
255 local
254 main
253 default
0 unspec
1 net1
2 net2
3 net3
2) Created rules in RPDB:
ip rule add from 192.168.1.101 table net1
ip rule add from 192.168.2.101 table net2
ip rule add from 192.168.3.101 table net3
3) Added routes in new route tables:
ip route add 192.168.4.0/24 table net1 scope global via 192.168.1.102 dev eth1 src 192.168.1.101
ip route add 192.168.1.0/24 table net1 scope link dev eth1 src 192.168.1.101
ip route add 192.168.4.0/24 table net2 scope global via 192.168.2.102 dev eth2 src 192.168.2.101
ip route add 192.168.2.0/24 table net2 scope link dev eth2 src 192.168.2.101
ip route add 192.168.4.0/24 table net3 scope global via 192.168.3.102 dev eth3 src 192.168.3.101
ip route add 192.168.3.0/24 table net3 scope link dev eth3 src 192.168.3.101
Now I can ping all eth1, eth2 and eth3 of UBUNUT1 from UBUNTU3, but still I am unable to ping 192.168.4.103 (eth1) of UBUNTU3 from eth1 or eth2 or eth3 of UBUNTU1.