2016年8月4日 星期四

CentOS 7 修改主機名稱 - hostnamectl

以下文章摘自http://blog.xuite.net/tolarku/blog/359546118-CentOS+7+%E4%BF%AE%E6%94%B9%E4%B8%BB%E6%A9%9F%E5%90%8D%E7%A8%B1+-+hostnamectl+

在之前的 CentOS 或其他的 Unix 主機,想要修改主機名稱可以使用「hostname」指令。但到 CentOS 7 之後,雖然 hostname 指令還在卻沒作用了,去修改 /etc/sysconfig/network 也沒作用 ...... 這是因為他改用了「hostnamectl 」指令了。

hostnamectl - Control the system hostname

# 查看目前的主機名稱 #
hostnamectl

$ hostnamectl
Static hostname: localhost.localdomain
Transient hostname: web2
Icon name: computer
Chassis: n/a
Machine ID: 927683d8736xx3345622b982d75
Boot ID: 8226be1192e74w532525c235325f38
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-229.20.1.el7.x86_64
Architecture: x86_64

# 設定主機名稱 #
hostnamectl  set-hostname   [NAME]

$ hostnamectl  set-hostname www
==== AUTHENTICATING FOR org.freedesktop.hostname1.set-static-hostname ===
Authentication is required to set the statically configured local host name, as well as the pretty host name.
Authenticating as: root
## 這個功能是 CentOS 7 提供的新作法,假設一般使用者要執行需要 root 權限的指令,他會跳出要你輸入 root 的密碼來做驗證,驗證過當然就執行囉!....這跟以往直接跟你說需要 root 權限不一樣。

$ sudo hostnamectl  set-hostname www
[user@www ~]$

有這個指令之後,就不用再去修改 network 設定了,直接一行指令搞定,重開機也不會改變了。

 >> 這個動作會寫入到 /proc/sys/kernel/hostname 設定檔裡

----------------
另外針對主機名稱多了「icon-name」、「chassis」

set-icon-name [NAME]
Set the system icon name. The icon name is used by some graphical applications to visualize this host. The icon
name should follow the Icon Naming Specification[1]. Pass an empty string to this operation to reset the icon name
to the default value, which is determined from chassis type (see below) and possibly other parameters.

set-chassis [TYPE]
Set the chassis type. The chassis type is used by some graphical applications to visualize the host or alter user
interaction. Currently, the following chassis types are defined: "desktop", "laptop", "server", "tablet",
"handset", as well as the special chassis types "vm" and "container" for virtualized systems that lack an
immediate physical chassis. Pass an empty string to this operation to reset the chassis type to the default value
which is determined from the firmware and possibly other parameters.

~End

沒有留言: