文章目录
  1. 1. 檢視主機名稱
  2. 2. 修改主機名稱

檢視主機名稱

使用 hostnamectl 來檢視主機名稱相關資訊,如下:

1
2
3
4
5
6
7
8
9
10
11
12
root@bobochen-vm [01:22:14 AM] [~]
-> $ hostnamectl
Static hostname: bobochen-vm
Icon name: computer-vm
Chassis: vm
Machine ID: OOOXXX78a943ae8f3cc26602e3
Boot ID: OOOXXXc0a48a89974cb4b6a66a
Virtualization: xen
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.22.2.el7.x86_64
Architecture: x86-64

來看一下官方手冊說明:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
NAME
hostnamectl - Control the system hostname
SYNOPSIS
hostnamectl [OPTIONS...] {COMMAND}
DESCRIPTION
hostnamectl may be used to query and change the system hostname and related settings.
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 is a default received from network configuration. If a static hostname is set, and is valid (something
other than localhost), then the transient hostname is not used.
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.
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-info(5).
Use systemd-firstboot(1) to initialize the system host name for mounted (but not booted) system images.

修改主機名稱

使用 hostnamectl set-hostname [Host Name] 來修改主機名稱

1
$ hostnamectl set-hostname server-www1

設定後,我們可以再用 hostnamectl 檢查看看是否生效。

文章目录
  1. 1. 檢視主機名稱
  2. 2. 修改主機名稱