User avatar
rin67630
Posts: 463
Joined: Fri Mar 04, 2016 10:15 am

Suggestion: Reporting ip address in /boot/boot.ip

Thu Jun 27, 2019 3:13 pm

One's problem on working headless, is frequently to know the IP address that the raspberry has got from the router.
The best approach to get it from the routers DHCP info is not always possible.
Would'nt it be a good practise to report the IP assigned during the boot process in a text file called e.g. boot.ip in the fat boot partition?
So one could easily read that info (or error messages if not successful) from the sd-card on any computer and use it to ssh at the second attempt.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23385
Joined: Sat Jul 30, 2011 7:41 pm

Re: Suggestion: Reporting ip address in /boot/boot.ip

Thu Jun 27, 2019 3:25 pm

Interesting idea.

You could manually do this by having a job running on startup that dumps the results of ifconfig to file.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

User avatar
rin67630
Posts: 463
Joined: Fri Mar 04, 2016 10:15 am

Re: Suggestion: Reporting ip address in /boot/boot.ip

Thu Jun 27, 2019 3:35 pm

I mean to have it at the very initial run with no configuration, straight from Balena Etcher.
You can give in the wpa_supplicant credentials in /boot , so it would boot into WLAN, but you need the IP to do everything else.

Andyroo
Posts: 4211
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Suggestion: Reporting ip address in /boot/boot.ip

Thu Jun 27, 2019 4:05 pm

The Pi supports zero-config (Zeroconf) networking via avahi from first boot.

If your machine is equipped with the same (Macs have it via Bonjour, PCs via ITunes, Bonjour or later versions of Windows 10, Linux via lots of programs) then you do not need the IP address as you can just use raspberrypi.local to access it.

If you then change its name(good idea by the way), it still shows on the network as <newname>.local

More details can be found at https://www.linux.com/news/zero-configu ... king-linux
Need Pi spray - these things are breeding in my house...

Ernst
Posts: 1215
Joined: Sat Feb 04, 2017 9:39 am
Location: Germany

Re: Suggestion: Reporting ip address in /boot/boot.ip

Thu Jun 27, 2019 5:05 pm

rin67630 wrote:
Thu Jun 27, 2019 3:13 pm
One's problem on working headless, is frequently to know the IP address that the raspberry has got from the router.
The best approach to get it from the routers DHCP info is not always possible.
Would'nt it be a good practise to report the IP assigned during the boot process in a text file called e.g. boot.ip in the fat boot partition?
So one could easily read that info (or error messages if not successful) from the sd-card on any computer and use it to ssh at the second attempt.
How is this supposed to work ?
1) Boot Pi
2) Pull power
3) Put card in PC and find IP in boot partition
4) Put card in Pi
5) Power on
No what if the DHCP server decides to change the IP address because of a) lack of addresses or b) policy ?
There is no guarantee that the same IP address will be offered on the second boot
The road to insanity is paved with static ip addresses

User avatar
rin67630
Posts: 463
Joined: Fri Mar 04, 2016 10:15 am

Re: Suggestion: Reporting ip address in /boot/boot.ip

Thu Jun 27, 2019 6:20 pm

Ernst wrote:
Thu Jun 27, 2019 5:05 pm
No what if the DHCP server decides to change the IP address because of a) lack of addresses or b) policy ?
There is no guarantee that the same IP address will be offered on the second boot
I guess 99,9% of the private routers do assign IP addresses based on the mac and practically never change its address.
All my VNC clients run that way and I never experienced an address change, even if I never minded to chnge DHCP to fixed addresses.

User avatar
rin67630
Posts: 463
Joined: Fri Mar 04, 2016 10:15 am

Re: Suggestion: Reporting ip address in /boot/boot.ip

Thu Jun 27, 2019 6:24 pm

Andyroo wrote:
Thu Jun 27, 2019 4:05 pm
The Pi supports zero-config (Zeroconf) networking via avahi from first boot.

If your machine is equipped with the same (Macs have it via Bonjour, PCs via ITunes, Bonjour or later versions of Windows 10, Linux via lots of programs) then you do not need the IP address as you can just use raspberrypi.local to access it.

If you then change its name(good idea by the way), it still shows on the network as <newname>.local

More details can be found at https://www.linux.com/news/zero-configu ... king-linux

That might work... if you ensure that you always change the raspi's name immediately and you have got no other Pi with the initial name on the same network.

User avatar
rin67630
Posts: 463
Joined: Fri Mar 04, 2016 10:15 am

Re: Suggestion: Reporting ip address in /boot/boot.ip

Thu Jun 27, 2019 6:32 pm

rin67630 wrote:
Thu Jun 27, 2019 6:24 pm
That might work... if you ensure that you always change the raspi's name immediately and you have got no other Pi with the initial name on the same network.
No, it does not work.
Just used a fresh SD card from Balena, with wpa_supplicant adapted on /boot.
It boots into WLAN at a given IP address, VNC activated.
VNC runs well from the numeric IP, not from raspberrypi.local. "the given name is unknown".

Ping to raspberrypi.local brings the same error.
Ping to [MyComputerName].local works.

So it is clearly the Raspberry that does not have avahi enabled by default.

User avatar
rin67630
Posts: 463
Joined: Fri Mar 04, 2016 10:15 am

Re: Suggestion: Reporting ip address in /boot/boot.ip

Thu Jun 27, 2019 7:57 pm

jamesh wrote:
Thu Jun 27, 2019 3:25 pm
Interesting idea.

You could manually do this by having a job running on startup that dumps the results of ifconfig to file.
Thank you, how could I solve the permissions without jeopadizing the safety?

sudo ipconfig > /boot/boot.ip has a permission problem.

User avatar
rpdom
Posts: 15014
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Suggestion: Reporting ip address in /boot/boot.ip

Thu Jun 27, 2019 8:04 pm

The sudo only works on the line before the ">" so the redirect doesn't have permissions to write to that area.

Try this:

Code: Select all

sudo /bin/sh -c "ifconfig >/boot/boot.ip"
which includes the ">" in the sudo command.

Or you could put the command in /etc/rc.local and skip the sudo altogether, but that might not work if you haven't got "Wait for network" enabled in the configuration screen.

Andyroo
Posts: 4211
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Suggestion: Reporting ip address in /boot/boot.ip

Thu Jun 27, 2019 8:29 pm

rin67630 wrote:
Thu Jun 27, 2019 6:32 pm
rin67630 wrote:
Thu Jun 27, 2019 6:24 pm
That might work... if you ensure that you always change the raspi's name immediately and you have got no other Pi with the initial name on the same network.
No, it does not work.
Just used a fresh SD card from Balena, with wpa_supplicant adapted on /boot.
It boots into WLAN at a given IP address, VNC activated.
VNC runs well from the numeric IP, not from raspberrypi.local. "the given name is unknown".

Ping to raspberrypi.local brings the same error.
Ping to [MyComputerName].local works.

So it is clearly the Raspberry that does not have avahi enabled by default.
It does - did two machines yesterday - a Zero W with Stretch and a 3B+ with Buster :) :?: :)

Only times I’ve know this to fail are:
1) The host machine has not got zero-config on it (Windows 10 often seems to have problems - I use a Mac)
2) The ‘switch’ or access point is a Plus-net router. Spent weeks with their tech support to be told - stick the issue on the forum as we do not know!
Need Pi spray - these things are breeding in my house...

User avatar
rin67630
Posts: 463
Joined: Fri Mar 04, 2016 10:15 am

Re: Suggestion: Reporting ip address in /boot/boot.ip

Thu Jun 27, 2019 8:54 pm

Andyroo wrote:
Thu Jun 27, 2019 8:29 pm
It does - did two machines yesterday - a Zero W with Stretch and a 3B+ with Buster :) :?: :)
It does indeed. but without the .local suffix.

The .local suffix is for unixoides, Windows uses the plain name.

User avatar
rin67630
Posts: 463
Joined: Fri Mar 04, 2016 10:15 am

Re: Suggestion: Reporting ip address in /boot/boot.ip

Fri Jun 28, 2019 5:46 am

rpdom wrote:
Thu Jun 27, 2019 8:04 pm
The sudo only works on the line before the ">" so the redirect doesn't have permissions to write to that area.

Try this:

Code: Select all

sudo /bin/sh -c "ifconfig >/boot/boot.ip"
which includes the ">" in the sudo command.

Or you could put the command in /etc/rc.local and skip the sudo altogether, but that might not work if you haven't got "Wait for network" enabled in the configuration screen.

Code: Select all

sudo /bin/sh -c "ifconfig >/boot/boot.ip"
worked well.
I wonder if, placed as a shell command in /etc/init.d, it will come late enough to report the given address.
"wait for network" would block everything if the connection fails isn't it?

User avatar
rpdom
Posts: 15014
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Suggestion: Reporting ip address in /boot/boot.ip

Fri Jun 28, 2019 8:01 am

Wait for network will time out eventually, so everything will run. But it may take a few minutes extra to start up.

/etc/init.d is the old way of doing things. Everything is now under control of the MCP systemd.

User avatar
thagrol
Posts: 1777
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Suggestion: Reporting ip address in /boot/boot.ip

Fri Jun 28, 2019 10:57 am

rin67630 wrote:
Thu Jun 27, 2019 3:13 pm
One's problem on working headless, is frequently to know the IP address that the raspberry has got from the router.
The best approach to get it from the routers DHCP info is not always possible.
Would'nt it be a good practise to report the IP assigned during the boot process in a text file called e.g. boot.ip in the fat boot partition?
So one could easily read that info (or error messages if not successful) from the sd-card on any computer and use it to ssh at the second attempt.
There's a problem with that: it's not guaranteed to get the same IP address on the second boot. There's a high probability that it will but that depends on a number of factors including how long between boots, router/dhcp configuration, and whether the first and subsequent boots use the same network hardware.

Good idea in principle but not entirely reliable.
This space unintentionally left blank.

epoch1970
Posts: 3564
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Suggestion: Reporting ip address in /boot/boot.ip

Fri Jun 28, 2019 12:19 pm

Writing uselessly to the FAT partition is not the best idea for boot reliability and for random bits of trivia /opt is a better place than /boot.

A custom discovery+provisioning service could be interesting I think.
Let's say mDNS already has discovery sorted.
Every Pi could run a client sending/fetching config from, e.g. pi-master.local, the service name of the server. Some sort of Cloud-init.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

User avatar
thagrol
Posts: 1777
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Suggestion: Reporting ip address in /boot/boot.ip

Fri Jun 28, 2019 12:35 pm

epoch1970 wrote:
Fri Jun 28, 2019 12:19 pm
Writing uselessly to the FAT partition is not the best idea for boot reliability and for random bits of trivia /opt is a better place than /boot.
Yeah, but how many pi owners, especially those who need this functionality, have a PC that can read ext4 partitions? The point about writing to /boot is that it's a FAT partition and almost every device on the planet* that has the hardware to access uSD cards can handle FAT.

*: and atleast two off it.
This space unintentionally left blank.

epoch1970
Posts: 3564
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Suggestion: Reporting ip address in /boot/boot.ip

Fri Jun 28, 2019 7:58 pm

The current design is basic, it is also minimal. (Well it was until SSH had to be disabled out of the box)
Using the FAT partition as a user output area is not only futile (an IP address is volatile) and ill advised but in addition at runtime it means writing whatever you want in /boot...

The need for information/configuration on a headless machine is clear, but this proposition is not sound.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Andyroo
Posts: 4211
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Suggestion: Reporting ip address in /boot/boot.ip

Fri Jun 28, 2019 8:18 pm

Why not have a program or app like the power-line boxes that finds the part configured Pi and lets you set some config up?

Synology uses a web page http://find.synology.com - though they fall back to pulling bits from <device type>.local:5000 or a program if that fails...

Of course there is Balenas IoT WiFi connect tool
Need Pi spray - these things are breeding in my house...

User avatar
rin67630
Posts: 463
Joined: Fri Mar 04, 2016 10:15 am

Re: Suggestion: Reporting ip address in /boot/boot.ip

Fri Jun 28, 2019 8:22 pm

epoch1970 wrote:
Fri Jun 28, 2019 7:58 pm
... is not only futile (an IP address is volatile)...
MAY be volatile!
Practically, on 99,9% of the private routers, it is perfectly stable.
I use to run many many Pis on IP addresses with VCN and had NEVER EVER got the need to configure them specifically for a fixed address.
The Routers just keeep the IP tied to the MAC...

User avatar
rin67630
Posts: 463
Joined: Fri Mar 04, 2016 10:15 am

Re: Suggestion: Reporting ip address in /boot/boot.ip

Fri Jun 28, 2019 8:29 pm

Andyroo wrote:
Fri Jun 28, 2019 8:18 pm
Of course there is Balenas IoT WiFi connect tool
That one is not useful: writing the credentials in wpa_supplicant.conf in /boot/ is far easier and much faster.
Last edited by rin67630 on Fri Jun 28, 2019 9:10 pm, edited 1 time in total.

Andyroo
Posts: 4211
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Suggestion: Reporting ip address in /boot/boot.ip

Fri Jun 28, 2019 8:45 pm

Still having issues with the original need to be honest - with support for .local in one form or another on modern systems I’ve never struggled to find a Pi on the network when it’s configured correctly.

And when it’s not, it’s moments to fix the errors...
Need Pi spray - these things are breeding in my house...

User avatar
thagrol
Posts: 1777
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Suggestion: Reporting ip address in /boot/boot.ip

Fri Jun 28, 2019 8:48 pm

rin67630 wrote:
Fri Jun 28, 2019 8:22 pm
epoch1970 wrote:
Fri Jun 28, 2019 7:58 pm
... is not only futile (an IP address is volatile)...
MAY be volatile!
Practically, on 99,9% of the private routers, it is perfectly stable.
I use to run many many Pis on IP addresses with VCN and had NEVER EVER got the need to configure them specifically for a fixed address.
The Routers just keeep the IP tied to the MAC...
99.9% is a little strong, it's unlikely that you have experience of that many routers. And it depends on a number of factors (see my post above).

An IP address assigned via DHCP is volatile regardless of your personal experience unless explictly configured otherwise.

If the machine is on when the lease expires it'll probably get the same address back but if not it may not. That depends on the ration between the number of client machine and the size of the address pool, and whether any additional machine have connected in the mean time.
This space unintentionally left blank.

User avatar
rin67630
Posts: 463
Joined: Fri Mar 04, 2016 10:15 am

Re: Suggestion: Reporting ip address in /boot/boot.ip

Fri Jun 28, 2019 9:04 pm

OK to summarize, the best way to start comfortably a raspberry pi zero headless without any additional hardware would be:
-Get the image
-Burn the image with Balena etcher.
-Create a file in the /boot/ directory named wpa_supplicant.conf with this content:

Code: Select all

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=«your_ISO-3166-1_two-letter_country_code»

network={
    ssid="«your_SSID»"
    psk="«your_PSK»"
    key_mgmt=WPA-PSK
}
(mind the country code must be in capitals).
-Create an empty file named ssh.

Your SD card is ready to start.
Before you run it, on the PC (a recent Win10) make sure that you have got no other raspberrypi in the network:

Code: Select all

ping raspberrypi
(on a Mac or an unixoid,

Code: Select all

ping raspberrypi.local
)
You should not get any match.

Put the SD card into the raspberry Pi Zero headless, start it and wait a moment.

On your PC repeat the ping command.
You should now be able to get the IP from the ping.

Then you can SSH into your freshly started Pi Zero. User: pi, Password: raspberry
With

Code: Select all

sudo raspi-config
you can enable VNC, change the computer name, the password, increase the screen resolution
then

Code: Select all

sudo reboot
Then you can VNC into your PiZero and do the rest comfortably with a full desktop.

knute
Posts: 462
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Suggestion: Reporting ip address in /boot/boot.ip

Fri Jun 28, 2019 9:14 pm

I do a lot of development on a Windows 10 machine. I use it to burn my SD cards. I've installed Bonjour but for the life of me can't get it to find other computers on the network with their hostname.

What I think would be the slickest setup for people that have lots of Pis running headless using DHCP is to have a program that sends out a UDP packet on the broadcast address with their hostname and IP. You could listen using Wireshark or write a simple program to listen for ID packets and would know right away what computers were up and running. I don't know what is involved in getting a program added to the OS distribution, maybe somebody can enlighten? That way, you start your headless Pi and in a bit you have its address. If it changes on the next boot, you've still got it.

Return to “Raspbian”