在 Linux 中查看主机名有多种方式,以下是常用方法:
hostname 命令(最常用)hostname
只显示主机名。
hostnamectl(推荐,适用于 systemd 系统)hostnamectl
会显示:
/etc/hostname 文件cat /etc/hostname
这是系统启动时使用的主机名。
/etc/hostscat /etc/hosts
可以看到主机名与 IP 的映射关系。
uname 命令uname -n
显示网络节点主机名。
$ hostnamectl
Static hostname: server01
Icon name: computer-vm
Chassis: vm
Machine ID: xxxxx
Boot ID: xxxxx
Operating System: Ubuntu 22.04 LTS
Kernel: Linux 5.15.0
Architecture: x86-64
如果你需要修改主机名,也可以告诉我,我可以一步步教你。