在Ubuntu系统中设置主机名可以通过以下几种方法:
hostname
或 hostnamectl
来查看当前主机名。sudo hostname 新主机名
。将“新主机名”替换为您期望的主机名。这种方式修改的主机名在系统重启后将恢复为原先的主机名称。编辑 /etc/hostname 文件:
/etc/hostname
文件:sudo nano /etc/hostname
。编辑 /etc/hosts 文件:
/etc/hosts
文件:sudo nano /etc/hosts
。应用新的主机名:
sudo hostnamectl set-hostname 新的主机名
。将“新的主机名”替换为您实际设置的主机名。重启系统:为了使主机名的更改生效,您需要重启Ubuntu系统:sudo reboot
。
通过以上步骤,您应该能够在Ubuntu系统中成功设置主机名。