Ubuntu主機名的規則遵循以下幾點:
長度限制:
字符集:
保留字:
localhost
、localhost.localdomain
等。唯一性:
域名兼容性:
ubuntu-host
, myserver-01
, webserver-123
-ubuntu
, ubuntu-
, ubuntu host
, my server
, 123ubuntu!
臨時設置: 在終端中輸入以下命令可以臨時更改主機名:
sudo hostnamectl set-hostname new-hostname
永久設置:
編輯/etc/hostname
文件:
sudo nano /etc/hostname
將文件中的舊主機名替換為新主機名,并保存退出。
更新/etc/hosts
文件(如果需要):
sudo nano /etc/hosts
確保新主機名與IP地址的映射關系正確無誤。
重啟系統以使更改生效:
sudo reboot
遵循以上規則和建議,您可以為您的Ubuntu系統設置一個合適且有效的主機名。