用别的ubuntu系统镜像导入创建的虚拟机,会继续沿用之前的主机名hostname。为了不与原系统混在一起,需要修改主机名hostname。
hostnamectl
举例
minigame@minigame-dev:~$ hostnamectl
Static hostname: minigame-dev
Icon name: computer-vm
Chassis: vm
Machine ID: 9d8b1b5ed4134c55b0809bc4dde92169
Boot ID: 901501f4ddd04f9595be47375edceb44
Virtualization: vmware
Operating System: Ubuntu 20.04.2 LTS
Kernel: Linux 5.4.0-70-generic
Architecture: x86-64
sudo hostnamectl set-hostname <新host name>
举例
sudo hostnamectl set-hostname abin-01
如果查看hosts文件,可以看到127.0.0.1还没有解析到新的hostname
cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 minigame-dev
sudo vi /etc/hosts
127.0.0.1 localhost
127.0.1.1 abin-01 <--- 这里填新的hostname
hostnamectl
Static hostname: abin-01
Icon name: computer-vm
Chassis: vm
Machine ID: 9d8b1b5ed4134c55b0809bc4dde92169
Boot ID: 901501f4ddd04f9595be47375edceb44
Virtualization: vmware
Operating System: Ubuntu 20.04.2 LTS
Kernel: Linux 5.4.0-70-generic
Architecture: x86-64