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. I am referring this https://github.com/arpitjindal97/raspbian-recipes/blob/master/wifi-to-eth-route.sh
2 Answers
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.
-
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
or edit/etc/sysctl.conf
and uncomment the appropriate setting Commented 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 Commented 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.– IngoCommented 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
Commented 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– glkadaCommented Sep 12, 2020 at 6:38
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.
net.ipv4.ip_forward=1
in/etc/sysctl.conf