zoukankan      html  css  js  c++  java
  • Change the HostName of CentOS 8

    There are three classes of hostname: static, pretty, and transient.
    static - The traditional hostname. It is stored in the /etc/hostname file and can be set by the user.
    pretty - A free-form UTF8 hostname used for presentation to the user. For example, Rusking's desktop.
    transient - A dynamic hostname that is maintained by the kernel. DHCP or mDNS servers can change the transient hostname at run time. By default, it is the same as the static hostname.

    It is recommended to use a fully-qualified domain name (FQDN ) for both static and transient names such as host.example.com.

    1. 查看当前主机的hostname

    [root@centos8 ~]# hostnamectl
    Static hostname: centos8
    Icon name: computer-vm
    Chassis: vm
    Machine ID: 611133c4577f4388a7892c32df056c74
    Boot ID: 7376f5f7f2314132a3f3f7ec0aeee06d
    Virtualization: oracle
    Operating System: CentOS Linux 8 (Core)
    CPE OS Name: cpe:/o:centos:centos:8
    Kernel: Linux 4.18.0-193.el8.x86_64
    Architecture: x86-64

    [root@centos8 ~]# cat /etc/hostname
    centos8
    [root@centos8 ~]# hostnamectl --static
    centos8
    [root@centos8 ~]# hostnamectl --transient
    centos8
    [root@centos8 ~]# hostnamectl --pretty

    2. 修改主机名
    [root@centos8 ~]# hostnamectl set-hostname centos8.test.com --static (不加static也可以,默认就是static。)
    [root@centos8 ~]# hostnamectl set-hostname "rusking's Test CentOS8" --pretty
    [root@centos8 ~]# hostnamectl set-hostname centos8.test.com --transient
    [root@centos8 ~]# hostnamectl --static
    centos8.test.com
    [root@centos8 ~]# hostnamectl --pretty
    rusking's Test CentOS8
    [root@centos8 ~]# hostnamectl --transient
    centos8.test.com
    [root@centos8 ~]# hostnamectl
    Static hostname: centos8.test.com
    Pretty hostname: rusking's Test CentOS8
    Icon name: computer-vm
    Chassis: vm
    Machine ID: 611133c4577f4388a7892c32df056c74
    Boot ID: 7376f5f7f2314132a3f3f7ec0aeee06d
    Virtualization: oracle
    Operating System: CentOS Linux 8 (Core)
    CPE OS Name: cpe:/o:centos:centos:8
    Kernel: Linux 4.18.0-193.el8.x86_64
    Architecture: x86-64

    3. 也可以在nmtui界面修改。

    [root@centos8 ~]# nmtui

    输入nmtui命令后,出现如下界面,选择“Set system hostname". 

                                                         ┌─┤ NetworkManager TUI ├──┐
                                                         │                         │
                                                         │ Please select an option │
                                                         │                         │
                                                         │ Edit a connection       │
                                                         │ Activate a connection   │
                                                         │ Set system hostname     │
                                                         │                         │
                                                         │ Quit                    │
                                                         │                         │
                                                         │                    <OK> │
                                                         │                         │
                                                         └─────────────────────────┘

    设置完成之后,需要重启systemd-hostnamed.service生效。 

    [root@centos8 ~]# systemctl restart systemd-hostnamed.service 

    上述两种方式修改完主机名之后,/etc/hostname会自动更新。但是需要手动检查并修改/etc/hosts文件中配置的hostname。

  • 相关阅读:
    解决:oracle+myBatis ResultMap 类型为 map 时返回结果中存在 timestamp 时使用 jackson 转 json 报错
    jackson @ResponseBody 处理日期类型的字段
    spring 中 InitializingBean 接口使用理解
    idea 中如何生成类图
    阿里云centOS 重启后 重启应用步骤
    日期类型 通过JOSN.stringify 后时间倒退8小时问题
    centOS7 下 安装mysql8.x
    Linux下卸载mysql8.x版本
    服务器上 MySql 8.0.16创建远程连接账号、获取初始密码、修改密码、重启命令等
    vue中读取excel中数据
  • 原文地址:https://www.cnblogs.com/rusking/p/13449377.html
Copyright © 2011-2022 走看看