最近遇到的hostname问题

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
onlylove
论坛版主
帖子: 5369
注册时间: 2007-01-14 16:23

最近遇到的hostname问题

#1

帖子 onlylove » 2025-06-01 0:02

最近发现虚拟机里面的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
回复