2

My Rpi-2 is connected to my home router which assigns an IP address 192.168.0.x to all its clients. I have created a network bridge on this rpi so that it shares the main routers connection with the terminal connected to the eth0 of the rpi. The rpi assigns it an IP of 192.168.2.x. I want to access terminal which is connected to the main router and getting an IP 192.168.0.x. What should I do? I have attached a small diagram for better intuition. enter image description here I am referring this https://github.com/arpitjindal97/raspbian-recipes/blob/master/wifi-to-eth-route.sh

4
  • so the pi would have a .0.x wifi address and a .2.x address on ethernet? Sep 11, 2020 at 10:06
  • Yes and the user also has 0.x and wants to access the dvr which has 2.x
    – glkada
    Sep 11, 2020 at 10:27
  • add a route 192.168.2.0/24 to the main router via the 192.168.0.x address of the pi (which you haven't mentioned) ...the router specific stuff is not answerable as we have no information about your main router ... and allow ipv4 routing on the pi (look for net.ipv4.ip_forward=1 in /etc/sysctl.conf Sep 11, 2020 at 10:29
  • Absolutely correct @JaromandaX
    – glkada
    Sep 11, 2020 at 12:30

2 Answers 2

2

A terminal is usually a monitor with a keyboard and mouse attached to a computer device. I assume you do not mean that, but a computer device like a PC, Laptop or smartphone. You also write that you use a network bridge on the RasPi. This isn't possible with a WiFi client connection to the router because lack of hardware support of the on-board WiFi chip. You have a routing configuration.

With routing the traffic between interfaces wlan0 and eth0 on the RasPi you have mainly two options: setting a static route on the Main Router, or use NAT (Network Address Translation) on the RasPi. NAT is simpler to setup because you do not have to reconfigure the Main Router, but it has restrictions. From theDVR you can connect to all devices on your local network, but not the way around. Device USER cannot connect to DVR. If this is acceptable then you can execute these commands on the RasPi:

rpi ~$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
rpi ~$ echo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Now you should be able to ping USER from DVR.

To get routing complete working you have to set a static route on the Main Router so it knows that it must send packages for 192.168.2.0/24 to the RasPi. Because the RasPi then has a gateway on 192.168.0/24 to its subnet 192.168.2.0/24, the gateway address must be static so it can be simple addressed. Give wlan0 on the RasPi a static ip address, e.g. 192.168.0.2. On most internet router you can set a static route but how to do that varies from model to model. It's up to you to find it out. Then on your router the gateway (next hop) is 192.168.0.2, destination network is 192.168.2.0/24 (or 192.168.2.0 netmask 255.255.255.0).

That means for the Main Router: "send all packages belonging to subnet 192.168.2.0/24 (destination network) to the next router on my subnet, the RasPi with ip 192.168.0.2 (gateway). It knows where to go on."

On the RasPi you also have to set:

rpi ~$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

Then you should be able to also ping DVR from USER (and the way around). All devices should be able to connect to each other.

You may also find some ideas at Share Ethernet printer on Wi-Fi that is similar to your problem.

8
  • echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward or edit /etc/sysctl.conf and uncomment the appropriate setting Sep 11, 2020 at 12:37
  • using NAT won't allow USER to access DVR (which is what the OP wants - not the other way around) - your second option will work, but DVR will have no access to the internet - since the router, without further configuration, probably only does NAT for the 192.168.0.0/24 subnet Sep 11, 2020 at 12:41
  • @JaromandaX What make you think, that the OP wants to connect from USER to DVR? I cannot find that in the question. For internet access the static route on the Main Router should be sufficient. The NAT on the router remembers the source ip of outbound packages (e.g. 192.168.2.34) and will route returned packages of this stateful connection (destination ip 192.168.2.34 after translation) according to the static route. Internet access should work for subnet 192.168.2.0/24. On all my router this works.
    – Ingo
    Sep 11, 2020 at 16:41
  • I read his comment on his post Yes and the user also has 0.x and wants to access the dvr which has 2.x Sep 12, 2020 at 0:45
  • Yes the user on 0.x wants to access the dvr on 2.x. The connectivity with internet is obviously mandatory
    – glkada
    Sep 12, 2020 at 6:38
-2

You have to enter your router settings and search for your device MAC. Then set that as a static IP. Then also make a static port and then configure your router. Then you can register the IP in the router and enter rpi from that terminal. The thing is you have to know what to do with your router. I am sorry for not giving you any details since I use a different router(per say). You may find these options in advance MAC binding settings.

1
  • But how will that help me the user access the DVR
    – glkada
    Sep 11, 2020 at 10:26

Your Answer

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

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