1

I'm using Libreelec on a RPi3 and I would like to use it to route between eth0 and wlan0 too.

  • Network A - 192.168.0.0/24 with Internet access, connected to eth0, my network
  • Network B - 192.168.1.0/24 with Internet access, connected to wlan0, friend's network

Basically I would like to "merge" the two networks with the Pi, so I can access my friend's network (just for file sharing directly, not for Internet access) and he can access mine whenever the Pi is switched on. Consider these sample devices:

  • Router_A = IP 192.168.0.1 + DHCP server (192.168.0.50-250) + Static route (192.168.1.0 MASK 255.255.255.0 192.168.0.112 METRIC 2)
  • PC_A = IP 192.168.0.77 (reseved on DHCP of Router_A), received default gateway 192.168.0.1
  • RPi eth0 = IP 192.168.0.112 (reserved on DHCP of Router_A), received default gateway 192.168.0.1
  • RPi wlan0 = IP 192.168.1.253 (reserved on DHCP of Router_B), doesn't seem to receive the default gateway even though Router_B provides it (and this should be correct, as eth0 is primary, right?)
  • PC_B = IP 192.168.1.99 (reserved on DHCP of Router_B), received default gateway 192.168.1.1 + Static route (192.168.0.0 MASK 255.255.255.0 192.168.1.253 METRIC 2)
  • Router_B = IP 192.168.1.1 + DHCP server (192.168.1.50-250), doesn't handle static routes so I had to add one to PC_B

Network layout

After connecting to my RPi via SSH and typing these commands (read from here):

LibreELEC:~/downloads # echo 1 > /proc/sys/net/ipv4/ip_forward
LibreELEC:~/downloads # iptables -F
LibreELEC:~/downloads # iptables -X
LibreELEC:~/downloads # iptables -t nat -F
LibreELEC:~/downloads # iptables -t nat -X
LibreELEC:~/downloads # iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE

... from PC_A and every other device on the network A I'm able to ping and connect to any PC or device on network B.

My issue is that the reverse is not true: from PC_B I can't ping PC_A or Router_A, only RPI wlan0. But PC_B has the static route added manually! Of course from the RPi via SSH I can ping any device on both networks.

What's wrong? I'm pretty sure something in iptables is missing, but I'm unable to figure out what, in particular.

NOTE: I don't need NAT specifically, this is the only setup that I've found working at the moment.

EDIT:

After Ingo answered, I learned the following which may be useful for future readers:

  1. The configuration was correct and only the ip_forward setting is necessary to make it work. NAT masquerade (last command) is not required.
  2. If from RPi you're not able to ping PC_B check that the firewall has the correct rule on PC_B or disable the firewall.
  3. Even after allowing ping on the firewall (previous point), from PC_A you won't be able to ping PC_B (but RPi will ping PC_B). However, if from PC_A you try to reach a port opened on PC_B (such as a webserver) it will work; ping is not working due to the firewall of PC_B (if you disable it, ping will work too). Alternatively, you can enable NAT masquerading (last command) and in this way PC_A will ping PC_B even without disabling the firewall.
  4. When creating the manual static route on PC_B it doesn't matter if the priority number in route print is higher than the gateway route on Windows 10. It's just a visualization (wrong in my opinion).
  5. My issues were caused by something on Network B that I haven't identified yet (see comments below).

1 Answer 1

1

It is a bit effortful to follow only your textual description so I do not follow it in detail. But you are using network address translation (NAT). This only works in one direction, from the "inside" PC to the "outside" world. The outside devices cannot reach the inside PC. This principle is used on any internet router and also a security issue. You should check your setup, if the reverse connections that does not work have to pass the NAT backwards. This is not possible due to the nature of the address translation.

UPDATE regarding to your drawing:
Very informative picture now :) Looks very good so far, can't find big issues, except the NAT. Just omit setting the NAT using iptables. But you need ip forwarding with echo 1 > /proc/sys/net/ipv4/ip_forward. Don't touch that. There is no gateway shown at the wlan0 interface on the RasPi. That's correct. The RasPi should only use one gateway (default route) on interface eth0 to its internet router 192.168.0.1. There is a static route set on PC_B whith route add 19.168.0.0 MASKI 255.255.255.0 192.168.1.253 METRIC 2. There is nothing wrong with it, but it's better to set this route on Router_B as you did on Router_A. This is a more general routing. Otherwise you have to set the static route on every device on Network B, that should connect to Network A.

7
  • I've tried to do my best to explain the network (will try to add an image soon), anyway I don't need a NAT (it's not mandatory) so I can remove it if I found a way to do in another way. Can you suggest something that does the routing forward and backward that I can try?
    – virtualdj
    Apr 6, 2020 at 6:08
  • @virtualdj Yes, I respect your effort to explain the network and I've upvoted it. But I have to translate the words into a picture in my mind and that isn't done at a glance ... A simple picture says more than thousand words. I'm confident that we will find a solution.
    – Ingo
    Apr 6, 2020 at 8:52
  • Thanks, I've edited the question with the graphical network diagram and a note about not needing NAT.
    – virtualdj
    Apr 6, 2020 at 17:13
  • @virtualdj I have updated the answer.
    – Ingo
    Apr 7, 2020 at 8:23
  • I know it's better to set the route on Router_B but unfortunately that router doesn't allow to :-( After your message, I tried to replicate the Network B configuration using another router and PC that I own and indeed it works... But not on my friend's setup. Probably there's something wrong there, but apart from the manual route to be set on the PC there is nothing more, right? I'll have to try again.
    – virtualdj
    Apr 7, 2020 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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