1

I'm trying to make an easy headless install image using this -> https://github.com/nmcclain/raspberian-firstboot

I've included

raspi-config nonint do_hostname myhostname

in the firstboot.sh script.

It does change the hostname on the Pi, but in my router when I look at the client list it still shows up as "raspberrypi", even after I reboot the pi, restart networking, etc. I had this pi previously assigned to a static IP from the router but I've removed the entry and disabled the manual assignment. My router is ASUS RT-AC1200. I'm starting to think the problem is in my router like there's some sort of cache or something that keeps assigning the "old" hostname because:

hostname

returns myhostname

  • In etc/hostname I have "myhostname", nothing else.
  • In etc/hosts I have "127.0.1.1 myhostname" as the last line.
  • I've tried to install Samba as someone suggested that on a StackExchange thread I found. That didn't work.
  • I've also tried to include numerous other commands (that I do not remember anymore), none of them worked. I've also tried another method of executing code on first boot -> https://gitlab.com/JimDanner/pi-boot-script/tree/master, but it caused a kernel panic.

I've been at this for like 6 hours today and a couple yesterday. I would really appreciate some help.

  • 1
    If the code you've downloaded from Github doesn't work, you should create an issue for the developer to report your bug and work with her/him to fix it. github.com/nmcclain/raspberian-firstboot/issues – Dougie Jan 12 at 16:09
  • No the code works fine (I think?), because I can see the hostname has changed on the Pi, it just doesn't change on the router. So the options are: 1. The command I've put in firstboot.sh doesn't change all instances of the hostname (there are multiple files where it needs to be changed and I've checked the ones I know and it was changed) 2. The router is assigning it's own hostname to the pi 3. ??? – Joseph Jan 12 at 16:20
  • Could be that you disabled avahi at some point, which probably how the router got the hostname initially. – goldilocks Jan 12 at 16:21
  • It might be useful. serverfault.com/q/102538/346256 – M. Rostami Jan 13 at 21:57
2

I assume you are using a dhcp client on the RasPi to get an ip address and configuration from a DHCP server on your network. DHCP clients have options to ask for a hostname on the network connection and depending on its configuration it may differ from the contents of /etc/hostname. It is possible to get a hostname from the DHCP server so you are able to manage hostnames at one place.

If you use default dhcpcd then you should have a look atman dhcpcd and search for keyword hostname. I had a glance at it but don't follow it in detail. You will find many hints what could manipulate the hostname. There are options and there are even hook scripts to manage the hostname.

| improve this answer | |
  • Isn't it related to the DHCP server on the router? I think the DHCP server recognizes the RPi by the MAC address, then, nothing would be efficient. (as this link.) – M. Rostami Jan 13 at 22:05
  • @M.Rostami I don't know what's efficient in the environment of the OP but there are options that the dhcp client must accept an offer of a hostname from the dhcp server. In man dhcpcd you find: "If the hostname is currently blank, (null) or localhost, or force_hostname is YES or TRUE or 1 then dhcpcd sets the hostname to the one supplied by the DHCP server." So a DHCP server can never just push hostnames to clients without enabled on the client. And I do not believe that the DHCP server identify a client also by its old ip address as described at the answer you have linked. – Ingo Jan 13 at 22:56
  • @M.Rostami It works on the link local layer (OSI layer 2) with mac addresses and an ip address is only an option that has to be send to the client. If the server identifies the old ip address if the mac address has changed then this is respected to the dhcp protocol and managed by the client, not by the server. The client request its old ip address and the server will accept it or offer a new one. You may have a look at Why does my Pi always have the same IP address? how this works. – Ingo Jan 13 at 22:56
  • "If the hostname is currently blank, (null) or localhost, or force_hostname is YES or TRUE or 1 then dhcpcd sets the hostname to the one supplied by the DHCP server. dhcpcd then daemonises and waits for the lease renewal time to lapse. It will then attempt to renew its lease and reconfigure if the new lease changes when the lease begins to expire or the DHCP server sends a message to renew early." So, @Joseph must wait for getting a dhcp_renew form the router? – M. Rostami Jan 13 at 23:04
  • 1
    With the given information it is speculation. My suggestion is to check the hostname issue against the possible different management by DHCP. – Ingo Jan 13 at 23:10

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.