1

I am attempting to put together a small Pi cluster which will sit behind another Pi. (See image)

RESTRAINTS: I do not have control over the Gateway, and the Main Pi static IP cannot be changed. Pi-A and Pi-B sit behind a switch, and need to be there own "set." Pi-A and Pi-B do not require access to the Gateway (internet), just access to the Main Pi.

What is the proper way to configure so I can SSH into the Main Pi, and then also be able to SSH into Pi-A and Pi-B from that same terminal? The three Pis will need to push and pull log information - storing data, eventually on the Main Pi. I have tried pinging both IP and Hostname of Pi-A and Pi-B with no luck.

Is there a way to do this without implementing some sort of dedicated server or is the way the subnet can be reached via hostnames? Can this all be done within dhcpcd.conf files or do I need to dance over to the Interfaces folder? Any help would be greatly appreciated. network-build

Ping Me
  • 11
  • 2

3 Answers3

2

You have a fatal error.

A gateway must be within the same IP subnet, thats the point with routing.

So the network 10.11.0.0/16 must have a gateway within 10.11.0.0/16 the IP network 172.16.0.0/24 must have a gateway within the 172.16.0.0/24 IP network.

So MAIN PI needs to have dual IP addresses, one within 10.11.0.0/16 and one in 172.16.0.0/24. And then you need to enable routing on MAIN PI.

Add an IP with the command: sudo ip addr add 172.16.0.3/24 dev eth0

And you need to enable routing: sudo nano /etc/sysctl.conf

Add the following line: net.ipv4.ip_forward = 1 this will make it permanent.

Reboot the Raspberry Pi or enable routing with: sudo sysctl net.ipv4.ip_forward=1

And then you need to cahange the PI-A and PI-B IP configuration to use 172.16.0.3 as default gateway.

MatsK
  • 2,882
  • 3
  • 17
  • 22
0

The Raspberry Pi OS (I believe since Jessie) uses dhcpcd to manage the network interfaces instead of the traditional networking service like other Linux distributions. The recommended method of setting a static IP (on either the ethernet or wlan interfaces) is to edit dhcpcd.conf . However, dhcpcd only supports a single static IP Address – you are out of luck if you need more.

So, you need to disable dhcpcd, re-enable the networking service, and edit the /etc/network/interfaces file. Before beginning this process, you will need to know your default gateway’s IP and what DNS servers you want to use since this info will be manually entered in /etc/network/interfaces.

If you are doing this re-configuration remotely, be sure to make all the edits before rebooting the RPi so you don’t leave it inaccessible.

Here is the original RPi interfaces file, including the original notes regarding dhcpcd.conf, edited with the new info:

# interfaces(5) file used by ifup(8) and ifdown(8)

Please note that this file is written to be used with dhcpcd

For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

12/20/21 - dhcpcd service disabled to allow multiple IP addresses on eth0

auto lo eth0 eth0:0 iface lo inet loopback

allow-hotplug eth0 iface eth0 inet static address 192.168.73.12/24

iface eth0:0 inet static address 192.168.1.100/24

gateway 192.168.73.1 dns-nameservers 192.168.73.2

Include files from /etc/network/interfaces.d:

#source-directory /etc/network/interfaces.d

Note that you are configuring a static IP for the eth0 interface (192.168.73.12) and a second static IP (192.168.1.100) using a new interface called eth0:0 . The new interface syntax is recognized by the networking service at boot and it will create the second IP for the RPi’s NIC.

If you want to do the same with the wlan0 interface instead of the eth0 interface, substitute wlan0 & wlan0:0 in the configuration above. Add this line to the end of the interfaces file, so your network’s WiFi credentials are configured properly (you may need to configure this file manually as well):

wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Now that the interfaces file is ready to go, you need to configure the services. First, disable dhcpcd:

$ sudo systemctl disable dhcpcd

Then, enable the networking service:

$ sudo systemctl enable networking

Now perform a reboot:

$ sudo reboot

Testing the new configuration. Run ifconfig -a to check the assigned IPs:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.73.12  netmask 255.255.255.0  broadcast 192.168.73.255
    inet6 fe80::ba27:ebff:feb9:7135  prefixlen 64  scopeid 0x20<link>
    ether b8:27:eb:b9:71:35  txqueuelen 1000  (Ethernet)
    RX packets 742587  bytes 51572238 (49.1 MiB)
    RX errors 0  dropped 242159  overruns 0  frame 0
    TX packets 8546  bytes 1113109 (1.0 MiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255 ether b8:27:eb:b9:71:35 txqueuelen 1000 (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 2 bytes 182 (182.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 2 bytes 182 (182.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Both eth0 & eth0:0 have been configured with the correct addresses.

This procedure is designed to be used from the Terminal on a remote system using ssh. If you are running the GUI on the RPi, it may disable the GUI configuration panels and force you to make all changes to /etc/network/interfaces and /etc/wpa_supplicant/wpa_supplicant.conf manually going forward.

Dougie
  • 5,381
  • 11
  • 22
  • 30
0

Creating a small private subnet for the three pi's is drop dead simple if they are all connected via an ethernet switch. All you have to do is assign them each an address.

Don't bother doing that via dhcpcd, the major purpose of which is to negotiate DHCP leases from a router. There is no router involved, just routes, which should be created automagically.

Presuming the eth interface is up:

ip address add 10.0.100.1/30 dev eth0

The ip address is arbitrary. The kernel should then add a route to the other possible addresses on that subnet (since /30 is used, there are only three possible addresses in total). You can check this via ip route, the output should include a line like:

10.0.100.0/30 dev eth0 proto kernel scope link src 10.0.100.1

If not, it is easy to create:

ip route add 10.0.100.0/30 dev eth0

This is for the first pi. The others are the same, except the address would be 10.0.100.2/30 and 10.0.100.3/30.

If you want to use hostnames, edit /etc/hosts and add, eg.

10.0.100.2    pi.two
10.0.100.3    pi.three

Again, this would be for the first pi and it lists the address of the other two. On this pi, you can now use pi.two and pi.three as hostnames for the other pis.

I don't think you are using the eth interface for the main Pi's gateway, as obviously if it is connected to the switch it can't be connected to anything else (unless there's another switch). In this case you should add to /etc/dhcpcd.conf:

denyinterfaces eth0

This way dhcpcd will ignore eth0 and things won't get mucked up by it.

The commands to add the address (and possibly the route) can be put in a boot script (eg., /etc/rc.local). You may want to include ip link set eth0 up before the other stuff.

What is the proper way to configure so I can SSH into the Main Pi, and then also be able to SSH into Pi-A and Pi-B from that same terminal?

You could set up forwarding on the main Pi but I do not think it is worthwhile. Instead, just nest two ssh sessions (ie., ssh to the main pi, then ssh from there to one of the other two using pi.[two|three] or the 10.0.100.x addresses).

goldilocks
  • 60,325
  • 17
  • 117
  • 234