Why is hostname and $HOSTNAME different?

Bo Berglund bo.berglund at gmail.com
Tue May 17 07:11:21 UTC 2022


On Wed, 11 May 2022 21:08:22 +0200, Bo Berglund <bo.berglund at gmail.com> wrote:

>On Wed, 11 May 2022 10:06:55 -0700, Tom Mitchell <niftyubuntu at niftyegg.com>
>wrote:
>
>>The easy answer first: Yes DHCP can set the hostname.  If that is how
>>you set it.
>>
>>Next search to see how you set the hostnames (yes plural) for your machine.
>>Start with /etc/hostname
>>Next /etc/hosts
>>Then DNS
>>Note that hostname is per network interface and that includes
>>localhost 127.0.0.1
>>I have different names and IP addresses for local loopback, wired
>>ethernet and WiFi.
>>
>>These are close enough to be a simple typo
>>  ubuntusrv
>>  ubuntuserv
>>
>
>I found this command on the net:
>
>$ hostnamectl
>   Static hostname: ubuntuserv
>Transient hostname: ubuntusrv
>         Icon name: computer-desktop
>           Chassis: desktop
>        Machine ID: f604e0e6137f58f8d2b3ebfc5a6fb461
>           Boot ID: db4430ae2f5847a29693c05e26a8e63e
>  Operating System: Ubuntu 20.04.4 LTS
>            Kernel: Linux 5.4.0-89-generic
>      Architecture: x86-64
>
>Notice the "transient hostname"!
>What is that?
>
>How can I get rid of the transient name?
>Well, I have now changed the DHCP entry in the router so it may get resolved
>next time it refreshes the lease.

But this is of course only a *workaround* to keep the hostname untouched!

Can someone here suggest some setting/configuration on the device itself that
will block any attempt from the DHCP server's side to set a hostname when
delivering an IP address?

I really do want the hostname set on the device itself to prevail also when
getting a new IP address lease from the DHCP server!


-- 
Bo Berglund
Developer in Sweden





More information about the ubuntu-users mailing list