×

INDI Library v2.0.7 is Released (01 Apr 2024)

Bi-monthly release with minor bug fixes and improvements

Linking two R-Pis with an ethernet cable

  • Posts: 643
  • Thank you received: 62
Hi all!

I'm currently using 2 R-Pis at my telescope, both connected to my LAN via wifi. For various reasons, I'd like to connect them to each other with an ethernet cable. I find ways to do that when searching the internet, but only by creating a separate subnet. What I would want is for both of them to be on my LAN. So I'd like to access the second, from my laptop on the LAN, via wifi to the first and then through the ethernet cable to the second.

In essence, I am using one as a wifi access point to which the second is connected with a cable...

Any ideas on how this could be implemented?

Magnus
3 years 2 months ago #66855

Please Log in or Create an account to join the conversation.

  • Posts: 1957
  • Thank you received: 420
Magnus,

Two distinct network interfaces (for instance eth0 for the fixed network and wlan0 for WIFI) can have IP addresses in the same subnet but the problem is that there can be only one route for that subnet. In general that route is via eth0 when both eth0 and wlan0 are connected. The reason is that the TCP/IP stack in the kernel needs to know how to reach other devices in the same subnet so if both network interfaces are in the same subnet then the network traffic should only be routed via one of the interfaces. This means that if a certain device can only be reached via one interface but the default route goes via the other, that certain device becomes unreachable.

I suppose you could set up a fixed ip address on eth0, delete the default route via eth0 and set it up to go vian wlan0 and then add a route via eth0 to our other rpi. That afaik would all have to be done manually though, or it would require quite a bit of scripting to make it possible. This is why a different subnet is suggested because that is much easier to set up.

I suppose you'd prefer not to use a different subnet so the second rpi can be connected to your home network as well if necessary?


Wouter
3 years 2 months ago #66856

Please Log in or Create an account to join the conversation.

  • Posts: 210
  • Thank you received: 104
If you want full connectivity on the second Rpi you need to run the routed service in the RPi with both connection to transform it in router. Then every computer in the network need to know the route to go to the other subnet.
There is other possibility if you not need full connectivity, for example using ssh tunnel to the first Rpi that end to the second. Or for http run a proxy on the Rpi with both connection.

This is not exactly your configuration but this can help to understand the router concept:
www.raspberrypi.org/documentation/config...cess-point-routed.md

Patrick
3 years 2 months ago #66857

Please Log in or Create an account to join the conversation.

  • Posts: 643
  • Thank you received: 62
Thanks!

Not trivial, that is one thing I realize.

Another option would perhaps be to have a wifi extender/access point at the telescope, to which the two Raspberrys could be connected with ethernet cables. If such a device exists that can run on 12 V.... ?

Main point here is that I want wifi from the house to the telescope, but high speed between the Raspeberries while also being able to control both via VNC from indoors.

Magnus
3 years 2 months ago #66859

Please Log in or Create an account to join the conversation.

  • Posts: 1957
  • Thank you received: 420
You could install WIFI mesh devices. Those are access point-like devices that replicate the WIFI network wherever you install them. I use them as well and have my Raspberry Pis at the telescopes connected to them via ethernet cables.
Last edit: 3 years 2 months ago by Wouter van Reeven.
3 years 2 months ago #66866

Please Log in or Create an account to join the conversation.

  • Posts: 348
  • Thank you received: 69
I think what you want to do here is create a layer-2 bridge between wlan0 and eth0 on the Pi that connects to your Wifi.

Then you can run a Ethernet cable between the two Pis and they should all appear to be on the same subnet.

The Pi wifi chipset has limitations on this, but there are some workarounds / hacks that you can search for:

raspberrypi.stackexchange.com/questions/...roxy-arp/88955#88955

raspberrypi.stackexchange.com/questions/...a-server/81518#81518
3 years 2 months ago #66876

Please Log in or Create an account to join the conversation.

  • Posts: 643
  • Thank you received: 62
OK, so what kind of mesh-device do you use? Preferably it should be one that could run on 12 V....

Magnus
3 years 2 months ago #66877

Please Log in or Create an account to join the conversation.

  • Posts: 1957
  • Thank you received: 420
I use TP-Link Deco M5 devices but I am pretty sure that any other will work fine as well.
Last edit: 3 years 2 months ago by Wouter van Reeven.
3 years 2 months ago #66881

Please Log in or Create an account to join the conversation.

  • Posts: 643
  • Thank you received: 62
Hi!

Thanks. I'll have a look at the briding-solution as well!

As for mesh-devices: I'm thinking that since I don't have a full observatory but take all electronics inside when not observing, it needs to be some device that I can easily disconnect and re-connect, and that works with my Ubiquity-network. This is not the kind of use mesh devices are designed for, really... so I'm curious about how well that would work. Do you leave your in place, or do as I do?

Magnus
3 years 2 months ago #66883

Please Log in or Create an account to join the conversation.

  • Posts: 1957
  • Thank you received: 420
I leave mine in place. Fortunately my backyard is not very big so I can connect my RPis to the mesh device inside my living room with a 10 meter ethernet cable.
3 years 2 months ago #66886

Please Log in or Create an account to join the conversation.

  • Posts: 276
  • Thank you received: 52
Check here for dual homing a PI
PI routing

I set up a PI ZeroW with its internal wifi and a dongle wifi
In your case it would be the eth0 interface

A very cryptic snippet of the commands I used

sudo apt-get install hostapd dnsmasq -y

My secondary network force set IP, secondary network serves DHCP to connected clients
sudo vi /etc/dhcpcd.conf
#interface wlan1
static ip_address=192.168.100.1/24
nohook wpa_supplicant # don't call the wpa_supplicant hook

cd /etc/
mv dnsmasq.conf dnsmasq.conf.orig
vi dnsmasq.conf
interface=wlan1
dhcp-range=192.168.100.2,192.168.100.20,255.255.255.0,24h



vi /etc/hostapd/hostapd.conf
vi /etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"

sudo systemctl unmask hostapd.service
sudo enable unmask hostapd.service
sudo systemctl enable hostapd.service
vi /etc/sysctl.conf
# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1

sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan1 -o wlan0 -j ACCEPT
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
vi /etc/rc.local
iptables-restore < /etc/iptables.ipv4.nat
3 years 2 months ago #66889

Please Log in or Create an account to join the conversation.

Time to create page: 0.357 seconds