1

I have setup three Ubuntu VMs in vmware. These are connected as:

enter image description here

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.

0

2 Answers 2

1

I have made it!

On UBUNTU1, I have my /etc/iproute2/rt_tables file as:

root@ubuntu-primary:/home# cat /etc/iproute2/rt_tables 
#
# reserved values
#
255 local
254 main
253 default
1   net1
2   net2
3   net3
0   unspec
#
# local
#
#1  inr.ruhep
root@ubuntu-primary:/home# 

I have created created rules with commands:

ip rule add from 192.168.1.101 table net1
ip rule add oif eth1 table net1
ip rule add from 192.168.2.101 table net2
ip rule add oif eth2 table net2
ip rule add from 192.168.3.101 table net3
ip rule add oif eth3 table net3

Now my rules in RPDB are as:

root@ubuntu-primary:/home# ip rule show
0:  from all lookup local 
32759:  from all oif eth3 lookup net3 
32760:  from all oif eth2 lookup net2 
32761:  from 192.168.3.101 lookup net3 
32762:  from 192.168.2.101 lookup net2 
32763:  from all oif eth1 lookup net1 
32765:  from 192.168.1.101 lookup net1 
32766:  from all lookup main 
32767:  from all lookup default 
root@ubuntu-primary:/home# 

Then I created routes in each tables, net1, net2 and net3 wit commands:

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 all three new route tables looks like:

root@ubuntu-primary:/home# ip route show table net1
192.168.1.0/24 dev eth1  scope link  src 192.168.1.101 
192.168.4.0/24 via 192.168.1.102 dev eth1  src 192.168.1.101 
root@ubuntu-primary:/home# 


root@ubuntu-primary:/home# ip route show table net2
192.168.2.0/24 dev eth2  scope link  src 192.168.2.101 
192.168.4.0/24 via 192.168.2.102 dev eth2  src 192.168.2.101 
root@ubuntu-primary:/home# 


root@ubuntu-primary:/home# ip route show table net3
192.168.3.0/24 dev eth3  scope link  src 192.168.3.101 
192.168.4.0/24 via 192.168.3.102 dev eth3  src 192.168.3.101 
root@ubuntu-primary:/home#

My main route table looks like:

root@ubuntu-primary:/home# ip route show table main
169.254.0.0/16 dev eth1  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 
root@ubuntu-primary:/home# 

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 enabled IP forward in UBUNTU2 with command:

echo 1 > /proc/sys/net/ipv4/ip_forward

And now everything working fine.

I can ping all eth1, eth2 and eth3 of UBUNTU1 from UBUNTU3, and I can ping eth1 of UBUNTU3 from UBUNTU1 with binding ping application to interface as:

ping 192.168.4.103 -I eth1
ping 192.168.4.103 -I eth2
ping 192.168.4.103 -I eth3
0

You cannot add two differents gateway to the same network.

From ubuntu1, you must define which interface will be the route to 192.168.4.X, you can go through either 192.168.1.102 or 192.168.2.102 or 192.168.3.102.

Once you've set routing by 192.168.1.102, the only way to route by 192.168.2.102 is to remove 192.168.1.102 and add 192.168.1.102.

Following your idea, you will add all three interface as gateway, now how can the system choose which gateway to use ? random one ? maybe you are looking for a dynamic routing protocol such as routed or gated ?

7
  • Yes correct, bu as I will bind socket on specific interface say eth1 or eth2 or eth3, the system must know that packet has to go out from that bound interface (we can say, system knows source address: 192.168.1.101 or 192.168.2.101 or 192.168.3.101). In order to route to 192.168.4.0/24, it has to send to correct gateway (192.168.1.102 or 192.168.2.102 or 192.168.3.102) according to bound interface. Isn't it?
    – nullptr
    Jul 21, 2015 at 11:48
  • So you want to open192.168.4.102, port 22 on eth1 and 192.168.4.102 port 80 on eth2 ? no way. If question is 192.168.4.122 port 22 on eth1 and 192.168.4.180 port 80 on eth2, that is possible, each host must be speocified on routing protocol.
    – Archemar
    Jul 21, 2015 at 11:52
  • why its not possible technically? I can't get it that its not possible. As I bind to different interfaces, system should know from which interface to go. If I bind to 0.0.0.0, then there can be problems.
    – nullptr
    Jul 21, 2015 at 11:55
  • May be using source address, and create different route tables, and rules in RPDB, but I didn't get it working.
    – nullptr
    Jul 21, 2015 at 11:56
  • Might the force (of internet) be with you !
    – Archemar
    Jul 21, 2015 at 12:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .