作者:E4b9a6, 创建:2021-06-16, 字数:943, 已阅:90, 最后更新:2024-03-10
对于Ubuntu1404后的Ubuntu系统,修改主机名无需再修改多处系统配置并重启系统
借助hostnamectl命令我们可以很方便的修改主机名且无需重启
查看主机名
ubuntu@my-machine:~$ hostnamectl status
Static hostname: my-machine
Icon name: computer-vm
Chassis: vm
Machine ID: 6ffef97fac51426e8e6741b4f8eb59eb
Boot ID: 6565db91b77645ec8ca7ea502819c547
Virtualization: kvm
Operating System: Ubuntu 18.04.4 LTS
Kernel: Linux 4.15.0-143-generic
Architecture: x86-64
修改主机名
ubuntu@my-machine:~$ sudo hostnamectl set-hostname my-machine-new
再次查看主机名
ubuntu@my-machine:~$ hostnamectl status
Static hostname: my-machine-new
Icon name: computer-vm
Chassis: vm
Machine ID: 6ffef97fac51426e8e6741b4f8eb59eb
Boot ID: 6565db91b77645ec8ca7ea502819c547
Virtualization: kvm
Operating System: Ubuntu 18.04.4 LTS
Kernel: Linux 4.15.0-143-generic
Architecture: x86-64