Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

修改 Linux 主機名稱完整步驟

編輯:Linux 教學

立即生效 (目前 Session)

hostname newhost

永久生效 (重開機保持)

vi /etc/sysconfig/network
# 修改或新增
HOSTNAME=newhost

更新 /etc/hosts 解析

vi /etc/hosts
127.0.0.1   newhost localhost
# 若有固定 IP,亦建議加入
192.168.1.10  newhost

否則 Apache、Postfix 等需解析主機名的服務啟動會失敗或報警。

提示字元立即更新

重新登入 (或開新終端) 即可看到新主機名。若不想登出,可執行 bash 重新載入環境。

systemd 系統 (RHEL 7+, CentOS 7+, Ubuntu 16.04+)

hostnamectl set-hostname newhost
# 同步更新 /etc/hostname、/etc/hosts、kernel 參數,無需手動編輯

驗證

hostname
hostname -f   # 顯示 FQDN
cat /etc/hostname
Copyright © Windows教程網 All Rights Reserved