命令hostnamectl

永久修改主机名:hostnamectl 永久主机名    是对/etc/hostname文件的内容进行修改

选项 说明
-H 操作远程主机
status 显示当前主机的信息,其实可以省略掉
set-hostname 设置系统主机名

查看主机信息

root@Kube-Master:~# hostnamectl status
Static hostname: Kube-Master
Icon name: computer
Machine ID: b4eb94eb0bc04946ae0a0382b1c78238
Boot ID: beb12766e8264e62aa24ddfb5b5fb32f
Virtualization: kvm
Operating System: Ubuntu Kinetic Kudu (development branch)
Kernel: Linux 5.19.0-15-generic
Architecture: x86-64
Hardware Vendor: QEMU
Hardware Model: Standard PC _Q35 + ICH9, 2009_
Firmware Version: 0.0.0

设置主机名称

root@Kube-Master:~# hostnamectl set-hostname xxxx