0

Running Raspbian 11 Bullseye on a Raspberry Pi 3 Model B Rev 1.2

I noticed (from getting a different prompt when re-logging in at one point) that something keeps futzing with the "transient" hostname, resetting it to localhost:

# hostnamectl status
   Static hostname: hg
Transient hostname: localhost
         Icon name: computer
        Machine ID: 5b33bf9eb66d440aaa7ed366eadef623
           Boot ID: 4b4c2bfec1f247648d815598a227a284
  Operating System: Raspbian GNU/Linux 11 (bullseye)
            Kernel: Linux 6.1.19-v7+
      Architecture: arm

If I manually set it myself, as with

# hostnamectl set-hostname --transient --static hg

and set up something to watch, something changes the transient hostname back to localhost, seemingly at random.

What's doing this, and how can I keep it from happening?

Thanks!

RoUS
  • 105
  • 5
  • What is the content of /etc/hosts? – Milliways May 06 '23 at 03:06
  • Per the man-page that's hostnamectl --transient --static hostname hg There is no ``set-hostnamecommand tohostnamectlSee [man 1 hostnamectl](https://man7.org/linux/man-pages/man1/hostnamectl.1.html) You can always do it the old way too# hostname hgthen# echo "hg" > /etc/hostnameand update/etc/hoststo contain the line127.0.0.1 hg.yourdomain.tld localhost hgand do the same for the::1` address for IPv6 loopback. – David C. Rankin May 06 '23 at 07:56
  • I disagree. The manpage for hostnamectl very clearly identifies "set-hostname NAME" as valid; it's the second command listed, after status. – RoUS May 06 '23 at 08:11
  • And /etc/hosts includes localhost for IPAs 127.0.0.1 and ::1. Which is as it should be The local address will always be there, and should always be named localhost. hg is known in DNS for the non-local address, so also assigning it in /etc/hosts to 127.0.0.1 will not make things any more simple; rather the opposite, ISTM. What is deciding that the transient hostname should be changed from whatever it might have been to localhost, and why? /etc/hostname does contain hg. – RoUS May 06 '23 at 08:16
  • It's an issue because the .bash_history file name includes the hostname, as does the bash prompt. Having those both use localhost defeats the purpose, but I believe it's the value of HOSTNAME envariable at time of login that sets what will be used. So it needs to be something a) predictable, b) persistent, and c) specific to that particular host. Does that help? – RoUS Jun 13 '23 at 03:41
  • I have been unable to track down what's been frobbing the hostname, so I've worked around it with a cron job to check and reset the name to the system's actual name, and not the navel-gazing value localhost. – RoUS Jul 25 '23 at 19:45

0 Answers0