Linux (Redhat / Fedora / CentOS) 更改 hostname 的方式

發現更改主機的 hostname 的方式都改不太完整. 以下是試出來比較完整的方式:

Step 00:

  • 假設原本 hostname 為 tryboxap2, 現在想要更改為 tryboxap03
  • 使用 root 才可以更改 hostname
su - root

Step 01:

  • 將 /etc/hosts 內出現的 tryboxap2 都改成 tryboxap03
vi /etc/hosts
127.0.0.1 tryboxap03 localhost.localdomain localhost

Step 02:

  • 將 /etc/sysconfig/network 內的 HOSTNAME 改成 tryboxap03
vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=tryboxap03
GATEWAY=61.67.71.126

Step 03:

  • 再使用 hostname 命令指定一次
hostname tryboxap03
  • 這時就已經設定完成. 可以使用 hostname 命令去確認一次
[root@tryboxap2 etc]# hostname
tryboxap03
[root@tryboxap2 etc]#

只要重新登入, 命令提示字串就會改成 [root@tryboxap03 etc]#

  • 如果有系統有設定自動寄出信件, 必須要重新啟動 sendmail 否則會出現 relay deny 的狀況
  • 如果要當郵件主機, hostname 就要符合 FQDN Exp. tryboxap03.ichiayi.com 所以 /etc/hosts 內要改成
    vi /etc/hosts
    127.0.0.1 tryboxap03.ichiayi.com tryboxap03 localhost.localdomain localhost
  • CentOS7 如果以上三步驟還無法改成功, 就需要在 /etc/hostname 這檔案內加入 hostname Exp. tryboxap03 或 tryboxap03.ichiayi.com
    vi /etc/hostname
    tryboxap03.ichiayi.com

<html><a href=“https://www.everplast.com.tw/”>Everplast – Your Reliable Extruder Machine Partner We Design We Care</a></html>

<html><a href=“http://www.diamonds2cash.com/diamond-buyer/”>diamond buyers</a></html>

  • tech/linux_hostname.txt
  • 上一次變更: 2019/10/24 09:27
  • jonathan_tsai