在Linux系统中,可以通过以下几种方法查看主机名:
hostnamectl命令hostnamectl
/etc/hostname文件cat /etc/hostname
/etc/sysconfig/network文件(适用于Red Hat系列系统)cat /etc/sysconfig/network
HOSTNAME一行,这就是你的主机名。hostname命令hostname
/etc/hosts文件cat /etc/hosts
localhost一行,通常会显示主机名。uname -n命令uname -n
以上方法适用于大多数Linux发行版,包括Ubuntu、Debian、CentOS、Fedora等。选择一种你觉得最方便的方法即可。