hostnamectl 主机名管理

发布时间: 更新时间: 总字数:243 阅读时间:1m 作者: IP上海 分享 网址

hostnamectl管理Linux主机名

介绍

  • Linux 主机名长度限制是 63 个字符
  • 该限制是由 Internet Assigned Numbers Authority (IANA) 定义的,它规定主机名需满足:
    • 小写字母数字连字符(-)的组合
    • 且以小写字母数字开头,以小写字母数字连字符结尾
  • 如果主机名是通过域名系统 (DNS) 解析的,它的长度还受到 DNS 协议的限制(一般为 255 个字符)

使用

hostnamectl -h

# 设置主机名,会写入 /etc/hostname
$ hostnamectl set-hostname cn-xiexianbin

# 查看主机名信息,等价于 hostnamectl status
$ hostnamectl
   Static hostname: cn-xiexianbin
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 62a45cd2213b47fe9d63b63df55297dd
           Boot ID: 415fb68e374045a09bc9815f4bf46e0a
    Virtualization: vmware
  Operating System: Ubuntu 20.04.5 LTS
            Kernel: Linux 5.15.0-82-generic
      Architecture: x86-64
  • 查看不同状态的主机名
# 瞬态的主机名
hostnamectl status --transient

# 静态的主机名
hostnamectl status --static

# 易读的主机名
hostnamectl status --pretty
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数