0

I'm putting multiple RPIs onto a subnet together connected via ethernet (all of them headless) using a switch and I want to be able to know what their IPs are when I first boot them. They won't be connected to a router or anything so they won't be assigned an IP.

Ideally I want to be able to edit /etc/dhcpcd.conf from the boot drive on the SD cards directly before booting the Pis for the first time. Alternatively, is there another way to set a static IP address from the boot drive?

  • You are putting multiple RPIs onto a subnet together connected via ethernet. So you have at least a switch, right? – Ingo Jul 9 '18 at 13:09
  • @Ingo yes, I'm using a switch – Matt Jul 9 '18 at 16:16
1

Normally I advise against static IP addresses, but an isolated network is one of the few valid use cases.

You can connect to the Pi over a direct Ethernet link to the Pi (not via a switch or router) using the Link-local address, although discovering this can be problematic.

You can easily connect from Linux and OS X with ssh pi@hostname.local (the default hostname is raspberrypi) This should work with popular GUI ssh programs. This is sometimes problematic with some versions of Windows and networks which use .local in a non-standard way. (See https://en.wikipedia.org/wiki/.local)

The other alternative is to assign an IP by including something like ip=192.168.0.10 in cmdline.txt. See https://elinux.org/RPi_cmdline.txt

I have not used the last in a modern Raspbian using dhcpcd, but it should still work, and should be replaced by a normal configuration.

PS accessing ext4 partitions from macOS is difficult, since the introduction of SIP. There may be 3rd party (paid) solutions which work.

  • Thanks! I tried adding ip=192.168.3.21 to the end of cmdline.txt from the boot partition on the SD card directly and it didn't seem to take affect. Is there another step I am missing? – Matt Jul 8 '18 at 5:09
  • @Matt Unfortunately I can provide no other ideas. I haven't used this for over 4 years (when Raspbian used Debian networking) - now I use raspberrypi.local if I need direct connection. You should provide more detail of EXACTLY your configuration. NOTE ssh is NOT enabled by default, and needs ssh on the boot partition. – Milliways Jul 8 '18 at 5:31
1

Here is an alternative solution to changing files on the ext4 SD-card, as it was suggested by Seamus:

  1. First you should connect your Raspberry Pi with another computer via Ethernet cable.

  2. After connecting your Raspberry Pi with another device (without a running DHCP server) via ethernet cable, on a new Raspbian installation your Raspberry Pi will have a self assigned link-local IP-address in the range of 169.254.1.0 to 169.254.254.255.

  3. Now the Ethernet interface on your computer also needs an IP address in the same subnet as the Raspberry Pi. If it did not self assign a link-local IP-address, you should set it yourself by choosing any in the range of 169.254.1.0 to 169.254.254.255.
    On Linux, e.g. use sudo ifconfig eth0 169.254.100.100

  4. Now you can directly ssh into your Raspberry Pi by

    ssh pi@raspberrypi.local

    and change the /etc/dhcpcd.conf file remotely.

If the raspberrypi.local addressing does not work, you need to search for the IP-address of your Raspberry Pi with a network scanner. On a Linux machine you can e.g. use arp-scan:

sudo arp-scan –interface=eth0 169.254.0.0/16

After finding the IP-address, you can now ssh into your Raspberry Pi.

1

We should be clear on terminology. When you say boot drive, are you referring to the SD card? That's fine, but know that there is a /boot partition on the SD card also (a *FAT filesystem), and it has a role in configuring some aspects of RPi when it is first booted. Unfortunately, setting static IP addresses can't be done in the /boot folder.

To edit the /etc/dhcpcd.conf file, you'll need to mount the root partition (/) of the boot drive (the SD card) using a system that can read the ext4 filesystem (e.g. you could remove it from your RPi, and mount it using an Ubuntu laptop). Another way would be to boot your RPi using a "live linux" thumb drive (Debian or Linux), and edit the file in situ.

  • yes I meant the SD card. Do you know if there is any way to read the ext4 filesystem from Mac? – Matt Jul 7 '18 at 20:19
  • I wouldn't try it on my Mac (REF), but there are some commercial tools that claim to do this (example), and here's a github page with some info. – Seamus Jul 7 '18 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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