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

Linux|Centos|Ubuntu|

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"

延伸 · 阅读

精彩推荐
  • Centoscentos7怎么查看cpu内存等系统性能参数?

    centos7怎么查看cpu内存等系统性能参数?

    centos7怎么查看cpu内存等系统性能参数?对centos系统不是很熟悉,想看看电脑的一些参数,该怎么查看呢?下面我们就来看看详细的查看教程,需要的朋友可以参考下...

    centos之家4522019-07-16
  • Centoscentos7修改网卡名字的方法

    centos7修改网卡名字的方法

    很多同学在装完centos7,发现网卡接口名字变了, 不再是eth*或者em*了,而是ens*,但是很不利于维护,下面小编给大家介绍下centos7修改网卡名字的方法,非常不错,一起看看吧...

    网络1872019-05-19
  • Centoscentos7安装后缺少网卡如何解决?

    centos7安装后缺少网卡如何解决?

    近期,发现centos7安装后缺少网卡。出现这种情况该如何解决呢,今天小编就为大家分享centos7安装后缺少网卡的解决方法,有需要的朋友一起去看看吧...

    centos之家2472019-05-24
  • Centos在CentOS系统上安装部署iSCSI客户端的教程

    在CentOS系统上安装部署iSCSI客户端的教程

    这篇文章主要介绍了在CentOS系统上安装部署iSCSI的教程,是一种基于Internet以及SCSI-3协议下的存储技术,需要的朋友可以参考下...

    运维生存时间2072019-09-05
  • Centoscentos7文件系统管理btrfs详解

    centos7文件系统管理btrfs详解

    Btrfs(又名:B-tree, Butter FS, Better FS),GPL授权, Oracle从2007研发,写实复制更新机制 CoW,其主要是为了取代ext2,ext3,ext4,今天小编为大家带来的是centos7文件系统管理btrfs详解;希望能够帮助到大家。有需要的朋友一起去看看吧...

    centos之家3562019-06-11
  • CentosCentOS下查看某个文件属于哪个包的方法

    CentOS下查看某个文件属于哪个包的方法

    一些朋友不知道CentOS下如何查看某个文件属于哪个包;下面小编将为大家分享CentOS下查看某个文件属于哪个包的方法;感兴趣的朋友一起去看看吧...

    脚本之家4132019-06-20
  • Centoscentos怎么将图形界面切换到命令行?

    centos怎么将图形界面切换到命令行?

    centos怎么将图形界面切换到命令行?centos系统中都是使用命令行操作的,用习惯了windows系统想要将命令行转换为图形界面,该怎么转换呢?下面我们就来看看详细的教程,需要的朋友可以参考下...

    服务器之家4062019-07-11
  • CentosCentOS有哪些常见的处理目录的命令?

    CentOS有哪些常见的处理目录的命令?

    一些朋友再问CentOS有哪些常见的处理目录的命令?今天小编将为大家分享CentOS几个常见的处理目录的命令详解,有需要的朋友一起去看看吧...

    未知4502019-06-12