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
  • 56,430
  • 17
  • 109
  • 217
dharcourt
  • 101
  • 1
  • 3
  • 1
    While I realise another user did ask you to edit in details (this is fine *if* it's before it would invalidate answers), I've rolled your question back because: 1) Your edits invalidated answers that had already been added. This is inconsiderate of other users, and confusing to posterity; in future, ask a new question if you are substantially changing the criteria, 2) Your final version of the question is really about how to scan a network with a chromebook, and has nothing much to do with the Pi, or the (more or less unchanged) title of the question. That makes it *off-topic* here. – goldilocks Aug 02 '18 at 12:31

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
  • 40,606
  • 15
  • 76
  • 189
  • Thanks for the answer, unfortunately I'm trying to set up Pi's with Chromebooks, which can't mount `ext4` file systems. It wouldn't make sense for me to maintain a Mac, Windows or Linux computer just to set up Pi's. On the other hand, I could use a pre-configured Pi for this (I'd set it up once with a borrowed Mac, Windows, or Linux system, then I wouldn't need Mac, Windows, or Linux other than the Linux on the Pi). I would however like to avoid if possible having to have a Pi around just to set up other Pi's. – dharcourt Apr 16 '18 at 03:48
  • Thanks also for the `nmap` idea. Although I couldn't use `nmap` from the Chromebook, I might be able to use Chrome's `chrome.socket` APIs to create an extension that would achieve a similar purpose, searching 169.254.*.* addresses for Pi's newly set up on the local network. I'll investigate... – dharcourt Apr 16 '18 at 03:50
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
  • 18,728
  • 2
  • 27
  • 57
  • @Ingo's solution might also work (I've not tried it), but of course you need a PC of some sort that can mount an EXT4 filesystem. Many Linux distros can, and I've heard Windoze PCs can do this, but again I've not tried it myself. I do know you can't mount EXT4 from OS X, and so that limits my range of approaches. – Seamus Apr 15 '18 at 17:28
  • Thanks for the detailed answer, however I'm looking for a solution that would avoid running Chromebooks in developer mode as this would negate many of the security benefits of using Chromebooks. Additionally most Chromebooks running in schools and enterprises are enrolled in GSuite and have their developer mode disabled. – dharcourt Apr 16 '18 at 03:58
  • 1
    You're welcome, and sorry that didn't help. If I could make a suggestion though: including *all* of your requirements in the OP would help us help you. I'd take another run at a solution, but frankly, after reading your comments to the two answers already provided, I am so unclear on what you're trying to do that I feel it would be a waste of time. – Seamus Apr 16 '18 at 12:39
  • @dharcourt You might check whether *arp* is available in *crosh* without enabling developer mode. Many such commands are, and I have no way to test. – Bob Brown Apr 17 '18 at 12:09
  • @BobBrown: _arp_ is unfortunately not available in _crosh_. A list of _crosh_ commands can be found online [here](http://krypted.com/commands/crosh-commands/) and [here](https://www.dell.com/support/article/us/en/19/sln293879/using-the-crosh-diagnostics-on-your-dell-chromebook?lang=en#Commands), though commands are occasionally added and removed over time and may vary by Chromebook model. My Chromebook's _crosh_ supports as subset of the commands listed online, and as far as I can tell none of those provides _arp_-like functionality. – dharcourt Apr 17 '18 at 17:10
  • @Seamus: Apologies for the lack of clarity in the original question. I've edited the question to clarify it a bit. Perhaps a simpler way to express it would be: "Is is possible to set up a Raspberry Pi with only a Chromebook?". Being able to set a Pi's static IP address from its `boot` partition would be one way to do that. – dharcourt Apr 17 '18 at 17:15