要修改Ubuntu的hostname,您可以使用以下方法之一:
方法1:使用hostnamectl命令(适用于systemd)
打开终端(快捷键:Ctrl + Alt + T)。
查看当前主机名:
hostnamectl
sudo hostnamectl set-hostname new-hostname
将new-hostname
替换为您想要的新主机名。
/etc/hostname
文件:sudo nano /etc/hostname
将文件中的旧主机名替换为新主机名,然后保存并关闭文件。
编辑/etc/hosts
文件:
sudo nano /etc/hosts
sudo reboot
方法2:使用sysctl命令(适用于非systemd)
打开终端(快捷键:Ctrl + Alt + T)。
查看当前主机名:
hostname
sudo sysctl --system --write-hostname=new-hostname
将new-hostname
替换为您想要的新主机名。
/etc/hostname
文件:sudo nano /etc/hostname
将文件中的旧主机名替换为新主机名,然后保存并关闭文件。
编辑/etc/hosts
文件:
sudo nano /etc/hosts
sudo reboot
完成上述步骤后,您的Ubuntu主机名将被成功修改。