服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Centos - CentOS7的hostnamectl命令使用详解

CentOS7的hostnamectl命令使用详解

2019-09-08 20:20运维之路 Centos

这篇文章主要介绍了CentOS7的hostnamectl命令使用详解,hostnamectl为CentOS7版本中新曾杰的命令,需要的朋友可以参考下

centos7 上在主机名变更新增了一个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


设置主机名

 

从上面的help 帮助里可以看到,在设置主机名时,这里涉及到四种主机名,在hostnamectl 的man手册里给予了说明和解释,如下:

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.
更改主机名

一般情况下都是使用set-hostname进行更改:
 

复制代码

代码如下:


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


更改主机名一般会涉及到/etc/hostname 、/etc/machine-info 两个文件,同时对于不同的名字修改在man手册上也给了说明:

 

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 设置的主机一般和图形界面会用到,对应的hostnamectl 输出中的Icon name  ,set-chassis 指定了主机的平台类型,如本机的是desktop,还可以设置为:"desktop", "laptop", "server", "tablet", "handset"

延伸 · 阅读

精彩推荐
  • Centos在CentOS系统上安装Docker的教程

    在CentOS系统上安装Docker的教程

    这篇文章主要介绍了在CentOS系统上安装Docker的教程,Docker是当下人气最为火热的容器类虚拟软件,需要的朋友可以参考下 ...

    开源中文社区3952019-09-17
  • CentosCentOS6.2网卡设置

    CentOS6.2网卡设置

    如果你想让服务器可以更新、让网友访问你的LINUX服务器,那一定要设置LINUX网上给网卡绑定一个IP,下面我们就介绍CentOS6.2网卡设置IP的方法。...

    CentOS教程网10092021-10-03
  • Centoscentos 7中添加一个新用户并授权的步骤详解

    centos 7中添加一个新用户并授权的步骤详解

    这篇文章主要给大家介绍了关于在centos 7中添加一个新用户并授权的步骤,文中将实现的步骤介绍的非常详细,通过文中介绍的步骤可以轻松的创建一个新...

    Ryan.Miao9832022-02-12
  • Centos使用Xshell连接Centos 6.6服务器操作图文教程

    使用Xshell连接Centos 6.6服务器操作图文教程

    这篇文章主要介绍了使用Xshell连接Centos 6.6服务器操作图文教程,本文用详细的操作步骤讲解了如何使用Xshell连接Centos服务器,需要的朋友可以参考下 ...

    脚本之家4032019-09-18
  • CentosCentOS7 阿里云的yum源使用详解

    CentOS7 阿里云的yum源使用详解

    这篇文章主要介绍了CentOS7 阿里云的yum源使用详解的相关资料,这里对备份yum源,添加EPEL源,和缓存清理,进行了介绍,需要的朋友可以参考下...

    天王9312020-12-28
  • CentosCentOS 最新版本git的安装教程

    CentOS 最新版本git的安装教程

    本文主要给大家介绍了CentOS 最新版本git的安装教程,非常不错,具有参考借鉴价值,感兴趣的朋友一起看看吧...

    CentOS教程网9252021-11-29
  • CentosCentOS系统下软件包的制作方法和过程详解

    CentOS系统下软件包的制作方法和过程详解

    今天小编将为大家带来的是CentOS系统下软件包的制作方法和过程详解;希望对大家会有帮助,有需要的朋友一起去看看吧...

    CentOS之家4802019-05-30
  • CentosCentOS上SVN服务器端程序的安装与使用教程

    CentOS上SVN服务器端程序的安装与使用教程

    SVN是一款高人气的软件项目版本控制系统,由于其在Windows的客户端的简易操作,在Git的浪潮中仍然保有很多的用户数量,这里我们就来看一下CentOS上SVN服务器端...

    cnblogs3902019-07-16