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

  • user warning: Table './zgq_smzz/blog_comments' is marked as crashed and should be repaired query: SELECT COUNT(*) FROM blog_comments c WHERE c.nid = 57 AND c.status = 0 in /home/www/zhouguoqiang/zhoume.org/modules/comment/comment.module on line 992.
  • user warning: Table './zgq_smzz/blog_comments' is marked as crashed and should be repaired query: SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data, c.thread, c.status FROM blog_comments c INNER JOIN blog_users u ON c.uid = u.uid WHERE c.nid = 57 AND c.status = 0 ORDER BY c.thread DESC LIMIT 0, 50 in /home/www/zhouguoqiang/zhoume.org/modules/comment/comment.module on line 992.

發現更改主機的 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

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 的狀況

原文链接:
http://www.ichiayi.com/wiki/tech/linux_hostname

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options