分页: 1 / 1

最近遇到的hostname问题

发表于 : 2025-06-01 0:02
onlylove
最近发现虚拟机里面的hostname突然变了,变成了vbox

看了下/etc/hosts和/etc/hostname,似乎没问题

最后搜索到的结论是,hostname不要用localhost,所以这个systemd……嗯……就这样吧,毕竟自己菜不是(我用localhost当hostname碍Lennart什么事了!

用hostnamectl看了下,显示的是transient hostname,这个transient hostname,可以是dhcp之类的从网络上获取的

https://unix.stackexchange.com/question ... -at-reboot
My problem (and the way I ended up here) was that I had the hostname set as the default localhost and according to the hostnamectl man page:

This tool distinguishes three different hostnames: the high-level "pretty" hostname which might include all kinds of special characters (e.g. "Lennart's Laptop"), the static hostname which is used to initialize the kernel hostname at boot (e.g. "lennarts-laptop"), and the transient hostname which is a default received from network configuration. If a static hostname is set, and is valid (something other than localhost), then the transient hostname is not used.

So a solution would be not to have the hostname set as localhost

Another solution is to make your dhcp configuration in /etc/dhcp/dhclient.conf not to request for a hostname by removing the host-name (and perhaps the domain-name) from the request property