在 Linux 中,查看 hostname(主机名) 有以下几种常用方法:
hostname
或
cat /etc/hostname
hostnamectl
输出示例:
Static hostname: myserver
Icon name: computer-vm
...
只查看主机名:
hostnamectl --static
hostname -f
或
hostname --fqdn
如果返回和
hostname一样,说明没有配置 FQDN。
cat /proc/sys/kernel/hostname
hostname 新主机名
sudo hostnamectl set-hostname 新主机名
然后:
sudo reboot
或在 /etc/hosts 中同步修改。
/etc/hostname/etc/hosts如果你愿意,可以告诉我你用的是 Ubuntu / CentOS / Debian / 容器环境,我可以给你更针对性的说明。