centos 7快速設定主機名稱指令hostnamectl介紹

來源:互聯網
上載者:User

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"

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.