I am attempting to ascertain and control actual hostname during dhcp AP association.

Changes to the /etc/hostname file break sudo.

An inspection of journalctl -u NetworkManager shows Network Manager consistently setting itself to the value in the above file. Dmesg association logs make no mention of hostname.

According to man NetworkManager.conf, Nm used to include a hostname option allowing hostname to be set per connection in the config file, but this is depracated (for some reason, implying perhaps there is a more obvious way to achieve the same functionality).

A hostname option also appears in dhclient.conf, much like the NetworkManager.conf option; but Network Manager still shows hostname being set to the value in /etc/hostname using hostnamed, regardless of dhclient.conf entry:

NetworkManager[9405]:[1595351700.9848] settings: hostname: using hostnamed
NetworkManager[9405]: <info>  [1595351700.9849] settings: hostname changed from (none) to "debian"

This seems a security fundament, at least if hostname can be sniffed or inspected in AP association logs.

What value is really being handed out at dhcp association, and how can it easily be controlled?

2 Answers 2


Maybe you have been looking at this problem wrong. If you just want one hostname, then you should be able to change it in /etc/hostname and everything else should work around it.

I have noticed that sometimes sudo complains after you change the hostname because it is unable to find the new hostname. I have added the hostname to /etc/hosts and that has fixed the issue.

You can add HOSTNAME to /etc/hosts by running echo " HOSTNAME" >> /etc/hosts (don't forget sudo if you need it). After that, I haven't had an issue with sudo and the hostname in /etc/hostname is used for networking like dhclient and such.

Hopefully that helps fix your problem.

  • Thanks for the answer. Indeed, I had of course tried just changing hostname and found it broke sudo as you suggest. I even spent half a day trying to get hostnamed to pass a different name on a network, and managed it, but with sudo continuing to break. I'll try adding the entry to hosts too.
    – Kebam
    Jul 23, 2020 at 18:58
  • I am still wondering why dhclient hostname specification fails - because Nm sets hostname instead as manager, I assume? And how hostname is registered, if at all, on local networks?
    – Kebam
    Jul 25, 2020 at 16:22

The answer seems to have been correct. Hostname can be changed with the top entry in hosts, reading hostname debian, changed to hostname [name], without breaking sudo.

$ sudo journalctl -u NetworkManager | grep hostname
NetworkManager[5592]: <info>  [1595532318.9762] settings: hostname: using hostnamed
NetworkManager[5592]: <info>  [1595532318.9763] settings: hostname changed from (none) to "debian"
NetworkManager[7887]: <info>  [1595538936.1117] settings: hostname: using hostnamed
NetworkManager[7887]: <info>  [1595538936.1117] settings: hostname changed from (none) to "vegetables"

In addition, it is clear that hostname is logged on local wireless networks, and OS apparently resolved:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .