CentOS7的hostnamectl命令使用詳解

centos7 上在主機(jī)名變更新增了一個(gè)hostnamectl 指令 ,該指令的無論在輸出和更改上都較之前更加的便利。先看下hostname的help幫助信息:
[root@361way ~]# hostnamectl --help
hostnamectl [OPTIONS...] COMMAND ...
Query or change system hostname.
-h --help Show this help
--version Show package version
--transient Only set transient hostname
--static Only set static hostname
--pretty Only set pretty hostname
-P --privileged Acquire privileges before execution
--no-ask-password Do not prompt for password
-H --host=[USER@]HOST Operate on remote host
Commands:
status Show current hostname settings
set-hostname NAME Set system hostname
set-icon-name NAME Set icon name for host
set-chassis NAME Set chassis type for host
查看hostname信息
[root@361way ~]# hostnamectl
Static hostname: 361way
Icon name: computer-desktop
Chassis: desktop
Machine ID: 6917731f5fe447d0bca296ed2802e250
Boot ID: e0d20bc2a3a4474c960394967d33ab53
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-123.6.3.el7.x86_64
Architecture: x86_64
設(shè)置主機(jī)名
從上面的help 幫助里可以看到,在設(shè)置主機(jī)名時(shí),這里涉及到四種主機(jī)名,在hostnamectl 的man手冊(cè)里給予了說明和解釋,如下:
This tool distinguishes three different hostnames: the high-level "pretty" hostname which might include all kinds of special characters (e.g. "Lennart's
Laptop"), the static hostname which is used to initialize the kernel hostname at boot (e.g. "lennarts-laptop"), and the transient hostname which might be
assigned temporarily due to network configuration and might revert back to the static hostname if network connectivity is lost and is only temporarily
written to the kernel hostname (e.g. "dhcp-47-11").
Note that the pretty hostname has little restrictions on the characters used, while the static and transient hostnames are limited to the usually accepted
characters of Internet domain names.
更改主機(jī)名
一般情況下都是使用set-hostname進(jìn)行更改:
[root@361way ~]# hostnamectl set-hostname blog
更改主機(jī)名一般會(huì)涉及到/etc/hostname 、/etc/machine-info 兩個(gè)文件,同時(shí)對(duì)于不同的名字修改在man手冊(cè)上也給了說明:
The static hostname is stored in /etc/hostname, see hostname(5) for more information. The pretty hostname, chassis type, and icon name are stored in /etc/machine-info, see machine-id(5).
set-icon-name 設(shè)置的主機(jī)一般和圖形界面會(huì)用到,對(duì)應(yīng)的hostnamectl 輸出中的Icon name ,set-chassis 指定了主機(jī)的平臺(tái)類型,如本機(jī)的是desktop,還可以設(shè)置為:"desktop", "laptop", "server", "tablet", "handset"
相關(guān)文章
虛擬機(jī)安裝CentOS后沒有網(wǎng)絡(luò)怎么辦
虛擬機(jī)安裝CentOS后沒有網(wǎng)絡(luò)了不能上網(wǎng),該怎么設(shè)置網(wǎng)絡(luò)呢?下面我們就來看看這個(gè)問題的解決辦法,詳細(xì)請(qǐng)看下文圖文介紹2024-01-18虛擬機(jī)怎么安裝CentOS? 安裝CentOS操作系統(tǒng)的保姆級(jí)圖文教程
虛擬機(jī)想要安裝CentOS操作系統(tǒng),但是CentOS操作系統(tǒng)已經(jīng)停止維護(hù)了,該怎么安裝呢?詳細(xì)請(qǐng)看下文圖文教程2024-01-18Centos7.8怎么更新openssh? Centos升級(jí)openssh的技巧
Centos7.8怎么更新openssh?Centos7.8系統(tǒng)想要安裝openssh,該怎么安裝呢?下面我們就來看看Centos升級(jí)openssh的技巧2023-09-02Centos7.8怎么更新openssl? CentOS升級(jí)OpenSSL的技巧
Centos7.8怎么更新openssl?Centos7.8系統(tǒng)想要升級(jí)OpenSSL,該怎么升級(jí)呢?詳細(xì)請(qǐng)看下文介紹2023-09-02- centos7沒有圖形化操作可能對(duì)很多人來說都不太習(xí)慣,下面我們來為centos7安裝圖形化界面,本文以安裝 GNOME 圖形化為例,需要的朋友可以參考下2023-06-29
- 今天小編在安裝RHEL7的時(shí)候,一步留神沒有安裝圖形化桌面,下面分享一下安裝圖形化桌面的過程,需要的朋友可以參考下2023-06-29
CentOS7各個(gè)版本鏡像下載地址及版本說明(包括Everything版)
下載CentOS-7.0-1406的時(shí)候,有很多可選則的版本,對(duì)于普通用戶來說,不知道選擇哪個(gè)好,下面做一下簡(jiǎn)單介紹,需要的朋友可以參考下2023-06-01Centos 7怎么手動(dòng)配置ip地址? Centos7配置IP地址的技巧
Centos 7怎么手動(dòng)配置ip地址?Centos 7系統(tǒng)想要自己配置ip地址,該怎么操作呢?下面我們就來看看Centos7配置IP地址的技巧2023-05-17- 這篇文章主要介紹了Centos 7 壓縮與解壓縮命令小結(jié),需要的朋友可以參考下2023-03-28
- 由于centos8 在2022年停止服務(wù),后繼版本為8-steam。在使用阿里云的 centos8 的 yum 時(shí)報(bào)錯(cuò),這篇文章主要介紹了CentOS8使用阿里云yum源異常的解決方法,需要的朋友可以參考2022-04-19