7
#ubuntu 修改主机名hostname
source link: https://xmanyou.com/ubuntu-change-hostname/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
10 April 2021
/ linux
#ubuntu 修改主机名hostname
用别的ubuntu系统镜像导入创建的虚拟机,会继续沿用之前的主机名hostname。为了不与原系统混在一起,需要修改主机名hostname。
1. 使用hostnamectl查看和修改
1.1. 查看 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
1.2. 修改hostname
sudo hostnamectl set-hostname <新host name>
sudo hostnamectl set-hostname abin-01
2. 修改本地域名解析
2.1. 查看 /etc/hosts
如果查看hosts文件,可以看到127.0.0.1还没有解析到新的hostname
cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 minigame-dev
2.2. 修改/etc/hosts
sudo vi /etc/hosts
127.0.0.1 localhost
127.0.1.1 abin-01 <--- 这里填新的hostname
3. 重新登录并验证
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
阿斌
Read more posts by this author.
扫一扫关注微信公众号:耿直的IT男阿斌
聊一聊IT男眼中的世界
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK