0

I'm setting up a Raspberry Pi Zero as an ethernet gadget using the instructions here.

That generally works but until I can log in to the Pi and configure it to use a static IP address it uses for its IP address a random one picked from the link-local range (169.254.0.1-169.254.255.255). Since I can't guess what that random address is I can't log in to the Pi to configure its static address or anything else.

This Pi is headless, so I can't log in to it directly to get its IP address or configure it to use a static address.

The Chromebook I'm configuring the Pi from doesn't support ZeroConf so I can't use raspberrypi.local instead of its IP address to reach the Pi.

Is there a way for me to set something up in the /boot partition of the Pi's microSD card to give it a static IP address on its first boot? Something similar to how wpa_supplicant.conf is copied from the /boot partition to /etc/wpa_supplicant?

If so, I could configure the static IP address for the Pi when I'm setting up its SD card. Needless to say, I can't modify that card's /rootfs from the Chromebook on which I'm doing this setup (Chrome OS can only mount ext4 partitions like /rootfs read-only).

Setting a static IP address from /boot would allow me to set up Pi Zeros using only Chromebooks, something which would be very useful when travelling and in classes.

goldilocks
  • 60,325
  • 17
  • 117
  • 234
dharcourt
  • 101
  • 1
  • 3

2 Answers2

4

If you can mount the root partition of your SD Card with the ext4 file system on a PC you simply can set a static ip address in /etc/dhcpcd.conf. There are some examples in it. You may consider to boot with a linux live system, e.g. from Debian or Ubuntu or SystemRescue or something else.

You can also use a network scanner running on your operating system. On Linux you can use nmap for example:

debian ~$ sudo nmap -sn 169.254.0.0/16 | grep -B 2 B8:27:EB

Here you will scan for devices from Raspberry Pi Foundation which MAC addresses start with OUI = B8:27:EB. Scanning about 65000 ip addresses in this example tooks a time. Maybe you can reduce the range if you can guess what subnet your ip address can be in, e.g. 169.254.7.0/24 with 255 ip addresses.

Update: 2019-11-09
Please note that the OUI of Raspberry Pi has changed to DC:A6:32.

Ingo
  • 42,961
  • 20
  • 87
  • 207
4

A Chromebook supposedly has a shell in "developer mode" :)

If you can get to that (i.e. get the $ prompt), enter this at the$ prompt:

arp -a | grep --ignore-case b8:27:eb

But if your RPi Zero is not in your arp cache that won't yield anything useful. If that's the case, then create the following file in your editor, save it as pingpong.sh:

#!/bin/sh

: ${1?"Usage: $0 ip subnet to scan. eg '192.168.1.'"}

subnet=$1
for addr in `seq 0 1 255 `; do
#   ( echo $subnet$addr)
( ping -c 3 -t 5 $subnet$addr > /dev/null && echo $subnet$addr is Alive ) &
done

make it executable:

chmod 755 ~/pingpong.sh

and then execute it (use your network address here, not necessarily 192.168.1.:

~/pingpong.sh 192.168.1.

Your output should look like this:

    192.168.1.11 is Alive
    192.168.1.19 is Alive
    192.168.1.28 is Alive
    ...
    192.168.1.255 is Alive
    192.168.1.0 is Alive

Now, your RPi Zero should be in your Chromebook's arp cache, so run arp as before:

arp -a | grep --ignore-case b8:27:eb

And you should then see something like this:

? (192.168.1.19) at b8:27:eb:3a:b9:78 on en0 ifscope [ethernet]

And so, for this case, the IP address of your RPi Zero is 192.168.1.19

Hope that helps... this code was executed on my MacBook, not on a Chromebook, so YMMV.

Seamus
  • 23,558
  • 5
  • 42
  • 83