4

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

  • Network A: 192.168.1.0 255.255.255.0
  • Network B: 192.168.2.0 255.255.255.0

The routers are:

  • 192.168.1.1
  • 192.168.2.1

Linux NICs are:

  • 192.168.1.2
  • 192.168.2.2

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 192.168.1.1: route add 192.168.2.0 255.255.255.0 gw 192.168.1.2

On 192.168.2.1: route add 192.168.1.0 255.255.255.0 gw 192.168.2.2

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

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

Giacomo1968
  • 3,542
  • 27
  • 38
user4104
  • 41
  • 1
  • 1
  • 2
  • 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 06 '14 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 06 '14 at 19:39
  • Have you configured any firewall rules? Post the output of `iptables-save` – fukawi2 Oct 17 '14 at 05:57

4 Answers4

4

You should set up the following static routes:

On 192.168.1.1 router:

192.168.2.0/24 next hop 192.168.1.2

On 192.168.2.1 router:

192.168.1.0/24 next hop 192.168.2.2

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.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
2

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 192.168.1.1;
  • All hosts in LAN B have their default gateway configured to 192.168.2.1;

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...

Cya!

Stefano Martins
  • 1,221
  • 8
  • 10
0

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

John
  • 9,070
  • 1
  • 29
  • 34
-1

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.

R.Sicart
  • 209
  • 1
  • 7