zoukankan      html  css  js  c++  java
  • centos8使用hostnamectl管理主机名称

    一,查看hostnamectl所属的包:

    [root@yjweb ~]# whereis hostnamectl
    hostnamectl: /usr/bin/hostnamectl /usr/share/man/man1/hostnamectl.1.gz
    
    [root@yjweb ~]# rpm -qf /usr/bin/hostnamectl
    systemd-239-13.el8_0.5.x86_64

    hostnamectl属于systemd这个包,

    默认情况下命令应该被系统内置了

    说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

             对应的源码可以访问这里获取: https://github.com/liuhongdi/

     说明:作者:刘宏缔 邮箱: 371125307@qq.com

    二,查看hostnamectl的版本和帮助

    1,查看版本

    [root@yjweb ~]# hostnamectl --version
    systemd 239
    +PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS 
    +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=legacy

    2,查看帮助

    [root@yjweb ~]# hostnamectl --help
    hostnamectl [OPTIONS...] COMMAND ...
    Query or change system hostname.
    
      -h --help              Show this help
         --version           Show package version
         --no-ask-password   Do not prompt for password
      -H --host=[USER@]HOST  Operate on remote host
      -M --machine=CONTAINER Operate on local container
         --transient         Only set transient hostname
         --static            Only set static hostname
         --pretty            Only set pretty hostname
    
    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 

    三,hostnamectl命令的使用例子

    1,查看当前的主机名称信息

    [root@yjweb ~]# hostnamectl status
       Static hostname: yjweb
             Icon name: computer-vm
               Chassis: vm
            Machine ID: 20191225112704604621388512217964
               Boot ID: f1f4511861e045cfba5744bc4ae584b9
        Virtualization: kvm
      Operating System: ;;https://www.centos.org/CentOS Linux 8 (Core);;
           CPE OS Name: cpe:/o:centos:centos:8
                Kernel: Linux 4.18.0-80.11.2.el8_0.x86_64
          Architecture: x86-64

    说明:直接使用 hostnamectl不加status参数也行

    2,把主机名修改为blog

    [root@yjweb ~]# hostnamectl set-hostname blog
    
    [root@yjweb ~]# hostnamectl
       Static hostname: blog

    查看效果:

    [root@yjweb ~]# more /etc/hostname
    blog

    退出后重新登录,则可以看到命令行提示符已生效:

    [root@yjweb etc]# exit
    logout
    [webop@yjweb ~]$ sudo -i
    [sudo] password for webop:
    [root@blog ~]#

    3,只查看static主机名:

    [root@blog ~]# hostnamectl --static
    blog

    4,修改pretty hostname并查看

    [root@blog ~]# hostnamectl set-hostname --pretty prettyblog
    [root@blog ~]# hostnamectl --pretty
    prettyblog

    说明:

    1,pretty hostname配置后保存在 /etc/machine-info文件中   

    [root@blog etc]# more /etc/machine-info
    PRETTY_HOSTNAME=prettyblog

    2,再次执行hostnamectl时也可看到Pretty hostname一项

    [root@blog etc]# hostnamectl
       Static hostname: blog
       Pretty hostname: prettyblog

    四,hostnamectl涉及到的文件

    1, Static hostname保存在 /etc/hostname 

    2, Machine ID保存在: /etc/machine-id

    五,三种定义的主机名:

    静态的(static)、瞬态的(transient)、和灵活的(pretty)。
    静态主机名也称为内核主机名,是系统在启动时从/etc/hostname内自动初始化的主机名。
    瞬态主机名是在系统运行时临时分配的主机名。
    灵活主机名则允许使用特殊字符的主机名

    看例子:

    "pretty"主机名:仅供人类阅读,可以包含各种特殊字符,且无长度限制。

                          例如"Lennart's Laptop"(必须是UTF-8编码)

    "static"主机名 : 用于在系统启动时设置内核的主机名,仅可包含 "-","a-z","0-9" 字符,

                            且最大不超过64个字符长度。

                            例如"lennarts-laptop"。

                            此种主机名就是通常所说的"主机名",存储在 /etc/hostname 文件中

    "transient"主机名:是从网络配置中获得的 fallback 主机名, 同样仅可包含 "-","a-z","0-9" 字符,

                              且最大不超过64个字符长度。

                            如果存在"static"主机名且不等于"localhost", 那么将忽略"transient"主机名

    六,查看centos的版本

    [root@blog ~]# cat /etc/redhat-release
    CentOS Linux release 8.0.1905 (Core) 
  • 相关阅读:
    mac os programming
    Rejecting Good Engineers?
    Do Undergrads in MIT Struggle to Obtain Good Grades?
    Go to industry?
    LaTex Tricks
    Convert jupyter notebooks to python files
    How to get gradients with respect to the inputs in pytorch
    Uninstall cuda 9.1 and install cuda 8.0
    How to edit codes on the server which runs jupyter notebook using your pc's bwroser
    Leetcode No.94 Binary Tree Inorder Traversal二叉树中序遍历(c++实现)
  • 原文地址:https://www.cnblogs.com/architectforest/p/12611939.html
Copyright © 2011-2022 走看看