Why is hostname and $HOSTNAME different?

Bo Berglund bo.berglund at gmail.com
Sat May 21 11:12:09 UTC 2022


On Tue, 17 May 2022 09:11:21 +0200, Bo Berglund <bo.berglund at gmail.com> wrote:

>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!
>

I received an off-list reply from a "Tom H" with a suggested solution, which I
will try out:

> I assume that you're using NM so "A" below should help you.
> 
> A) NetworkManager
> Two setups
> 1)
> Edit "/etc/NetworkManager/NetworkManager.conf"
> dhcp=internal
> hostname-mode=none
> 
> 2)
> Edit "/etc/NetworkManager/NetworkManager.conf"
> dhcp=dhclient
> hostname-mode=none
> Edit "/etc/dhcp/dhclient.conf"
> Remove "host-name" from "request ...;"

Since I do not know if NM is used I opened the conf file and found only this:

[main]
plugins=ifupdown,keyfile

[ifupdown]
managed=false

[device]
wifi.scan-rand-mac-address=no

So it seems like NM is not really in use...


> B) networkd
> AFAIK, its dhcp client doesn't have any option to control much.
> 
> C) ifupdown
> Edit "/etc/dhcp/dhclient.conf"
> Remove "host-name" from "request ...;"
> 

This file, on the other hand, contained more settings:

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, domain-search, host-name,
        dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
        netbios-name-servers, netbios-scope, interface-mtu,
        rfc3442-classless-static-routes, ntp-servers;
timeout 300;

So I have now removed the host-name, entry from line 2 of request.

Will cehck on the next reboot if this changes anything.


-- 
Bo Berglund
Developer in Sweden





More information about the ubuntu-users mailing list