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?

3
  • 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

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.

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!

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.

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

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.