LAN to LAN with different subnet

5,335

Solution 1

It's definitely possible, in fact it's the basis of how routing (routers) work. Through a variety of ways - static routes configured into a local router, updates via a protocol called RIP (Routing Information Protocol) which is essentially routers sharing their routing info, and if all else fails, Default Gateways (DG).

DGs are where traffic gets sent when the local router doesn't know where to send it - typically out of your LAN and to the ISP's router. Your PC will have your local router as it's DG, your router will have the ISP's router on it's WAN port as it's DG, and so on.

In the case you are asking about, each router would need to have a static route configured; which, if it were a Linux based router, you would do using commands something like this, with router 1 having a LAN IP Address of 192.168.0.1 and physical Ethernet port connected to the router 2 called 'eth3' and router 2 with IP Addr 10.0.0.1 connect to router 1 on LAN port 'eth0' (arbitrarily chosen) On router 1:

ip route add 10.0.0.0/24 via 192.168.0.1 dev eth3

and on router 2:

ip route add 192.168.1.0/24 via 10.0.0.1 dev eth0

Any PC connected to either of these routers trying to talk to the subnet it is not in would need to have the local router* set up as it's DG. DHCP typically configures this unless you are using static IPs.

If it had a different DG (and presumably multiple NICs) it would need to have a static route set up locally (e.g. 192.168.1.0/24 via [computers IP 10.0.0.x] dev [computers NIC connected to router 2]. The router would still need the same routes added from above in either case.

*technically the local routers LAN IP address

This site has a good write up on the concepts involved here: http://linux-ip.net/html/routing-intro.html

If you had RIP version 2 or other more sophisticated inter-router procotols, this routing info could be communicated between the routers without any additional configuration - see https://en.wikipedia.org/wiki/Routing_Information_Protocol

Solution 2

192.168.1.0/24 cannot talk directly to 10.0.0.0/24

If a device is only on 192.168.1.0/24 then the only way it can communicate with 10.0.0.0/24 is if some other device on 192.168.1.0/24 will help out by routing the traffic.

A reason for that restriction is that, in your example, the subnets don't overlap. A 192.168.0.0/16 can communicate with a 192.168.2.0/24, despite the subnets being different, because there is some overlap.

OLD: I have now answered the question that you asked. My guess is that I haven't fully answered what you wanted to know. If that's the case, feel free to ask another question.

UPDATE 1: Thanks for the helpful network diagram. My first inclination is to consider putting LAN2 on 192.168.1/24 and then make the routers act like switches. Commonly the easy way to do that is to plug things into the LAN ports. You may also need to tell the devices to just forward the Layer 2 traffic, and not try to perform Layer 3 routing. The result might be simpler.

However, that approach is not necessary, and we can do things the way that you're actually asking. With the current diagram, one LAN (which I'm going to rename, from "LAN" to "LAN1") is at 192.168.1/24 and LAN2 is 10/24.

Now, first I want to clarify a concept that I think you may not understand (because your current diagram looks a bit incomplete, since it shows only some of the IPv4 addresses that will need to be used). The 192.168.1/24 address used by your OpenWRT is typically not assigned to the entire OpenWRT device. The 192.168.1/24 address used by your OpenWRT is typically assigned to the specific network port. So the network port on the OpenWRT which communicates with LAN1 is using the 192.168.1/24 address, and the OpenWRT should have another IPv4 address that communicates with "MODEM". In truth, I don't really care what address is being used for the OpenWRT to connect to the MODEM (it might even be a public IPv4 address if the MODEM is using bridging), just as long as it's not in the same subnet as anything else we're using. e.g., if the OpenWRT is using 192.168.0/30 to connect to the modem, then that's fine because that subnet doesn't overlap with anything else that is being used elsewhere.

What is still needed are IPv4 addresses that the OpenWRT and the ZTE use to communicate with each other, over that "LAN to LAN" cable in your diagram. So assign that link a subnet and assign those network ports an address on the subnet. e.g., have OpenWRT use 192.168.2.1/30 and the ZTE use 192.168.2.2/30, or have the OpenWRT use 172.16.0.2/30 and the ZTE use 172.16.0.1/30.

Side note: You might notice I use an IPv4 /30 in some cases, instead of an IPv4 /24. The "/30" represents the subnet size; a /30 supports 2 devices well, and a /24 supports 254 devices well. I just mention a /30 when you can get away with using a small subnet. However, you could use a /24 instead of a /30, which doesn't really hurt. It may make some addresses be "wasted" because they aren't as easy to use, but the likely alternative is that they will just remain unused anyway, and you have literally millions of addresses, so it's fine to use either. If you want to better understand the topic, read further about subnet sizes (especially, see a "Variable Length Subnet Mask" chart, a.k.a. VLSM chart) and/or CIDR notation.

Then, try to have the OpenWRT and ZTE devices "ping" each other. Very often, devices configured with an internal web server will have a page that provides access to create a "ping" test.

I suggest you make sure that works before you try to get routing functional. Once every device can communicate with the neighboring devices, then start trying to make sure every device has the needed routes to get traffic to other devices on the network. If your PCs cannot communicate, try using a "ping" test to determine which network ports you can successfully ping on the remote devices.

You may need to adjust some firewalls (like the "Windows Firewall" software) to make sure devices can respond to ping. (If you have the available hardware, it may be helpful if you have a switch connect to one port on the router, and have multiple PCs connect to that switch, to see if the devices on the same subnet can ping each other. That can help determine whether devices respond to ping, without needing to worry as much about interference by a router.)

You might want to ask more questions about how to enable routing. However, I suggest that you don't even think about doing that until you assign all of the IPv4 addresses that you need to get assigned. Once you get those addresses assigned, you will probably help us well by providing an updated network diagram before asking other questions about how to get the routing working.

Share:
5,335

Related videos on Youtube

warheat1990
Author by

warheat1990

Updated on September 18, 2022

Comments

  • warheat1990
    warheat1990 over 1 year

    Is it possible to have 2 routers to communicate to each other via LAN to LAN (not LAN to WAN) despite both have different subnet?

    Topo:
    Router 1 (192.168.1.0/24)
    Router 2 (10.0.0.0/24)

    For example PC under Router 1 with IP address 192.168.1.180 will be able to communicate to PC under Router 2 with IP address 10.0.0.30.

    Diagram :

    https://i.imgur.com/wAivfed.png

    • Daniel B
      Daniel B about 8 years
      Are these networks physically separated or are they on the same broadcast domain?
    • prateek61
      prateek61 about 8 years
      Can you put a network diagram up as well?
    • warheat1990
      warheat1990 about 8 years
      check my first post
  • warheat1990
    warheat1990 about 8 years
    Can you guide me on how to route the traffic from 192.168.1.0 subnet to 10.0.0.0? My router is installed with OpenWRT. Also can you be more specific on subnet overlap or can you give me a link to read about this stuff?
  • Argonauts
    Argonauts about 8 years
    I just saw in your comment above that you are using openwrt. You can install iproutes2 on openwrt, which are the commands / syntax I used above. If put in the correct NIC names and IP addresses, they should work as-is.
  • warheat1990
    warheat1990 about 8 years
    Hey, I've followed your advice, but still cannot ping each other. Only one router is OpenWRT, the other isn't OpenWRT. Here's my settings : i.imgur.com/P5Jjkb1.png and i.imgur.com/O35GN18.png. What did I do wrong?
  • Argonauts
    Argonauts about 8 years
    The second router appears to be routing over the WAN interface. Is that how its wired? Also on the openwrt router it only lets you specify lan rather than specific phy device; that might be an issue. What model is the second router? Is the error on the ping a timeout or 'no route to host'? Does it change how it fails from one side to the other?
  • warheat1990
    warheat1990 about 8 years
    It's a ZTE F609, I'm afraid the is no LAN option on static route (screenshots.portforward.com/routers/ZTE/F660/Static_Routing‌​.htm). But here's some weird things I noticed, if I connect my device to ZTE, I'm getting the 192.168.1.0 address but not 10.0.0.0 address, that means the 2nd router has become a switch because the OpenWRT router is handling the DHCP even though DHCP is enabled in the 2nd router. Any idea why? My ultimate goal is that this ZTE must have its own IP because I need it as Samba server, but LAN to LAN is the only option because ZTE is a GPON ONT.
  • Argonauts
    Argonauts about 8 years
    The dhcp issue means that the route appears to be working. If you have multiple dhcp servers it's a race to see which one wins. Go with static ip addresses while looking into this if you can - at least on one side. When it gets assigned the incorrect dhcp server can it communicate to either subnet?
  • warheat1990
    warheat1990 about 8 years
    Yes, any devices connected to the ZTE can communicate with any devices under OpenWRT. But the problem is the ZTE itself does not get an IP, so I should change ZTE WAN connection to static instead of DHCP? I'll give it a try now. I just update my first post to show the diagram.
  • warheat1990
    warheat1990 about 8 years
    It works!! I just need to set the LAN option in ZTE to match the OpenWRT subnet and now everything can see each other!
  • Argonauts
    Argonauts about 8 years
    Great - I hadn't thought about the dueling dhcp server aspect. If you need dhcp on both ends you can probably block that traffic on the openwrt routers firewall