How to route ping packet from A to C?

I’m beginning understanding network concepts and tools. I setup three VM’s with the following configuration:


In A, I ping and it pongs. I think A has no idea where is located. So, when I ping, it doesn’t know to what interface it should be routed. My first question is that when there’s only one interface, why it wonders? 😀
Anyway, for route to take occur, in A I add the following:

sudo route add default enp0s3

I may use the following commands instead:

sudo route add default gw
sudo route add default gw
  1. Am I right in the commands?
  2. The last command also works! Why?! Is it correct?! How?!

With one of these commands A may ping too. Then, I go to ping C from A. I expect the ping packet when received by B, it knows how to route it and route it to C via 192.168.2.x interface, but it doesn’t.

  1. Why? Should I do something in B?
  2. What should I do in B for the ping to get response from C?


In order to achieve what you would like to have you need to do:

On A, you need to configure the route to 192.168.2.X, that is via

ip route add via

Note: you can specify a device name with dev DEVICE_NAME or you can omit it in this case.

On B, you need to make sure that packets can be forwarded e.g. ip_forwaring is enabled:

sysctl -w net.ipv4.ip_forward=1


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

In addition, you need to allow the traffic between the two networks in the firewall. So something like the following command should to the job:

iptables -I FORWARD -s -d -j ACCEPT
iptables -I FORWARD -s -d -j ACCEPT

B has two interfaces ( and and it already knows where to find both subnets. So in this case you don’t need to add additional routes on it.

On C, same as on A, you need to tell how to reach 192.168.1.X, that is via

ip route add via

And finally, you have to make all these changes permanent, because if you now reboot these nodes, the configuration which you have applied will be gone. How to achieve this depends on the Linux distribution you are using and is not in the scope of your current question 🙂

Source : Link , Question Author : hamidi , Answer Author : basekat

Leave a Comment