Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the hostnamectl command in CentOS7

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about how to use the hostnamectl command in CentOS7. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

A new hostnamectl instruction has been added to the hostname change on centos7, which is more convenient in terms of output and change than before. First, take a look at hostname's help help:

The code is as follows:

[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

View hostname information

The code is as follows:

[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

Set hostname

As you can see from the help help above, when setting the hostname, four hostnames are involved, which are explained and explained in hostnamectl's man manual, as follows:

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.

Change the hostname

In general, set-hostname is used to make changes:

The code is as follows:

[root@361way ~] # hostnamectl set-hostname blog

Changing the hostname usually involves two files, / etc/hostname and / etc/machine-info, and different name modifications are also described in the man manual:

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 settings are generally used for hosts and graphical interfaces. Icon name in the corresponding hostnamectl output, set-chassis specifies the platform type of the host, such as desktop, and can also be set to: "desktop", "laptop", "server", "tablet", "handset".

This is how the hostnamectl command in CentOS7 shared by Xiaobian is used. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report