TransWikia.com

How can hostname be controlled reliably in Linux?

Super User Asked by Kebam on November 12, 2021

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

The answer seems to have been correct. Hostname can be changed with the top entry in hosts, reading 127.0.0.1 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:

https://documentation.meraki.com/MR/Monitoring_and_Reporting/Hostname_Visibility

Answered by Kebam on November 12, 2021

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 "127.0.0.1 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.

Answered by sefodopo on November 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP