第一步
修改 hosts 文件
sudo nano /etc/hosts
修改 new_hostname 为新的主机名
GNU nano 4.8 /etc/hosts
127.0.0.1 localhost
127.0.1.1 new_hostname
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
第二步
修改 hostname 文件,替换为新的主机名
sudo nano /etc/hostname
第三步(关键)
一些云提供商可能安装了 cloud-init 包,Ubuntu 服务器也可能安装它,例如腾讯云服务器或轻量云服务器。如果已经安装了,你还需要编辑 cloud.cfg 文件