4

I have a Raspberry pi 3b that I am trying to change the hostname from the default of raspberry. Every time I change it and then reboot, the hostname is still raspberrypi.

os-release yields:

PRETTY_NAME="Raspbian GNU/Linux 10 (buster)" NAME="Raspbian GNU/Linux" VERSION_ID="10" VERSION="10 (buster)" VERSION_CODENAME=buster

uname -r yields: 5.10.17-v7+

The image on the SD card was created by using rpi-imager, on an RPI4, selecting Raspberry PI OS Lite (32-bit).

I tried changing the host name using raspi-config. I don't take the default reboot now so I can verify the change. If I cat /etc/hostname, I see the new hostname in the hostname file. I reboot and the hostname is raspberrypi again. I check /etc/hostname and see that the hostname is reverted back to raspberrypi.

I've also tried manually editing /etc/hostname, saving the edit, cat-ing /etc/hostname to verify that the change I made is there and it is. Reboot, and the change is lost; once again, /etc/hostname says raspberrypi.

Any ideas why this is happening?

Thanks in advance.

Dale
  • 43
  • 5

2 Answers2

4

First, like @Milliways said, check that your SD card is still OK. Create a file, reboot, and verify that the file is still there. Or try using the script @Ingo wrote.

If your SD card is writable, you might want to try setting the hostname the Debian way:

sudo hostnamectl set-hostname my_name
Dmitry Grigoryev
  • 28,277
  • 6
  • 54
  • 147
1

Using hostnamectl is a good start, but also check your network configuration on your router - sometimes raspbian will pick up the hostname that it reported to the router when it was first assigned an IP address. Most routers drop this table when they reboot, so rebooting your router could be the easiest fix.

One good option is to create a static DHCP entry for the Pi, using the hostname you would like. That way, from other machines on your network you can access it via hostname in addition to the IP address.

millerjs
  • 31
  • 3