I have a Linux box with two NICs, each connected to a different LAN:

  • Network A:
  • Network B:

The routers are:


Linux NICs are:


I want all hosts in network A to be able to ping all hosts in network B and vice versa.

What I've done so far:

On a Linux box: sudo sysctl -w net.ipv4.ip_forward=1

On route add gw

On route add gw

I tried it with two different linux distributions (Zentyal and Ubuntu) and nothing's working.

Hosts in network A can only ping, but can’t ping any of the other hosts in network B and vice versa. What am I doing wrong?

  • No idea, but this is a case where you need to look at a traceroute, and you need to fire up tcpdump. tcpdump is usually very useful for solving routing issues.
    – Zoredache
    May 6, 2014 at 17:07
  • Does NIC1 connect to ROUTER1 and NIC2 connect to ROUTER2? Or do both NICs connect to a switch that is then connected to ROUTER1 and ROUTER2?
    – CIA
    May 6, 2014 at 19:39
  • Have you configured any firewall rules? Post the output of iptables-save
    – fukawi2
    Oct 17, 2014 at 5:57

4 Answers 4


You should set up the following static routes:

On router: next hop

On router: next hop

This way the other computers in those networks send packets to their default gateway (.1), which then uses its static routing table entry to forward the packet to Linux box, which then forwards the packet to the other network.


If I got it right, you have this network:

+-------+       +----------+       +-----------+       +----------+       +-------+
| LAN A | <---> | Router A | <---> | Linux Box | <---> | Router B | <---> | LAN B |
+-------+       +----------+       +-----------+       +----------+       +-------+

So, this is true:

  • All hosts in LAN A have their default gateway configured to;
  • All hosts in LAN B have their default gateway configured to;

The fact is that neither the hosts in LAN A, nor the hosts in LAN B know the existence of other network, so they'll send the packet to the default gateway. If the default gateway knows it and has a route to get in there, they'll use it. So, basically, what you have to do is create these routes in your routers, or change the default gateway of your hosts to the Linux Box. You should go to the second option if your routers don't have the option of creating static routes or you simply don't have access to them.

If I got it wrong, please clarify a little bit...



You have to set the routes on the individual boxes in the other networks. So for example on, you have to route add gw


If your 2 networks are suposed to be connected directly to the Linux Box, you should add the routes in each host (and configure the default gateway if needed).

If networks are connected to routers which are connected through the Linux Box, you should configure for each host its right gateway (router 1 or 2) and configure routes in each router.

You should verify if Linux Box is blocking ICMP traffic too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.