一、检查本地系统版本
[root@server-01 ~]
NAME=CentOS Linux
VERSION=8 (Core)
ID=centos
ID_LIKE=rhel fedora
VERSION_ID=8
PLATFORM_ID=platform:el8
PRETTY_NAME=CentOS Linux 8 (Core)
ANSI_COLOR=0
CPE_NAME=cpe:/o:centos:centos:8
HOME_URL=https://www.centos.org/
BUG_REPORT_URL=https://bugs.centos.org/
CENTOS_MANTISBT_PROJECT=CentOS-8
CENTOS_MANTISBT_PROJECT_VERSION=8
REDHAT_SUPPORT_PRODUCT=centos
REDHAT_SUPPORT_PRODUCT_VERSION=8
二、hostname在Linux的帮助说明
[root@server-01 ~]# hostname --help
Usage: hostname [-b] {hostname|-F file} set host name (from file)
hostname [-a|-A|-d|-f|-i|-I|-s|-y] display formatted name
hostname display host name
{yp,nis,}domainname {nisdomain|-F file} set NIS domain name (from file)
{yp,nis,}domainname display NIS domain name
dnsdomainname display dns domain name
hostname -V|--version|-h|--help print info and exit
Program name:
{yp,nis,}domainname=hostname -y
dnsdomainname=hostname -d
Program options:
-a, --alias alias names
-A, --all-fqdns all long host names (FQDNs)
-b, --boot set default hostname if none available
-d, --domain DNS domain name
-f, --fqdn, --long long host name (FQDN)
-F, --file read host name or NIS domain name from given file
-i, --ip-address addresses for the host name
-I, --all-ip-addresses all addresses for the host
-s, --short short host name
-y, --yp, --nis NIS/YP domain name
Description:
This command can get or set the host name or the NIS domain name. You can
also get the DNS domain or the FQDN (fully qualified domain name).
Unless you are using bind or NIS for host lookups you can change the
FQDN (Fully Qualified Domain Name) and the DNS domain name (which is
part of the FQDN) in the /etc/hosts file.
三、hostname的中文帮助说明
用法:hostname[-b]{hostname |-F file}设置主机名(来自文件)
主机名[-a|-a|-d|-f|-i|-i|-s|-y]显示格式化名称
主机名显示主机名
{yp,nis,}域名{nisdomain |-F文件}设置nis域名(来自文件)
{yp,nis,}域名显示nis域名
dnsdomainname显示dns域名
主机名-V|
程序名称:
{yp,nis,}域名=主机名-y
dnsdomainname=主机名-d
程序选项:
-a、
-A、
-b、
-d、
-f、
-F、
-i、
-I、
-s、
-y、
描述:
此命令可以获取或设置主机名或NIS域名。你可以
还可以获取DNS域或FQDN(完全限定域名)。
除非您使用绑定或NIS进行主机查找,否则可以更改
FQDN(完全限定域名)和DNS域名(
FQDN的一部分)。
四、hostname命令的基本使用
1.查看计算机名
[root@server-01 ~]
server-01
2.查看本机上所有IP地址
[root@server-01 ~]
192.168.200.150 172.17.0.1 172.21.0.1 172.19.0.1 172.20.0.1
3.查看主机FQDN
[root@server-01 ~]
server-01
4.查看短主机名
[root@server-01 ~]
server-01
五、hostnamectl的使用
1.查看主机详细信息
[root@server-01 ~]
Static hostname: server-01
Icon name: computer-vm
Chassis: vm
Machine ID: 8daa9318d5564417b557c0bf5b06c3b8
Boot ID: f45c90c8ca254ef28bf4da5b04bdafdf
Virtualization: kvm
Operating System: CentOS Linux 8 (Core)
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-240.10.1.el8_3.x86_64
Architecture: x86-64
2.设置主机名
[root@server-01 ~]
3.hostnamectl的命令帮助
[root@server-01 ~]# hostnamectl
hostnamectl [OPTIONS...] COMMAND ...
Query or change system hostname.
-h
-H
-M
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
set-deployment NAME Set deployment environment for host
set-location NAME Set location for host