CentOS7设置host name

步骤记录 云天 5年前 (2020-03-04) 195次浏览 0个评论

title: CentOS7设置host name
date: 2020-03-04 19:05:44
tags:

  • linux
  • 主机名设置
    categories:
  • CentOS 7配置与使用
    toc: true

    在必要时将CentOS 7的主机名设置为自己想要的名字。

CentOS7设置host name

环境说明:

  • 内核版本:3.10.0-1062.9.1.el7.x86_64

本文先使用命令方式将主机名修改为“localhost”,再使用修改文件的方式将主机名修改为“jarvis”,以此演示主机名的修改。

查看hostname

  • 方法一:‘hostname’命令
    [root@jarvis ~]# hostname
    jarvis
  • 方法二:‘hostnamectl’命令
    [root@jarvis ~]# hostnamectl
     Static hostname: jarvis
     Pretty hostname: Jarvis
           Icon name: computer-vm
             Chassis: vm
          Machine ID: bb303a4a8b1846ce9ac8531e1b67db9b
             Boot ID: 81745e108ae64db18eea055db0702bf6
      Virtualization: kvm
    Operating System: CentOS Linux 7 (Core)
         CPE OS Name: cpe:/o:centos:centos:7
              Kernel: Linux 3.10.0-1062.9.1.el7.x86_64
        Architecture: x86-64

设置hostname

  • 使用命令设置

    hostnamectl set-hostname “主机名”

    [root@jarvis ~]# hostnamectl set-hostname localhost
    [root@jarvis ~]# hostname
    localhost
    [root@jarvis ~]# hostnamectl
     Static hostname: localhost
           Icon name: computer-vm
             Chassis: vm
          Machine ID: bb303a4a8b1846ce9ac8531e1b67db9b
             Boot ID: 81745e108ae64db18eea055db0702bf6
      Virtualization: kvm
    Operating System: CentOS Linux 7 (Core)
         CPE OS Name: cpe:/o:centos:centos:7
              Kernel: Linux 3.10.0-1062.9.1.el7.x86_64
        Architecture: x86-64
  • 通过修改配置文件设置
    [root@jarvis ~]# vim /etc/hostname    //打开此文件,将其中内容修改为“jarvis”
    [root@jarvis ~]# reboot       //修改文件的方式一定要自启
    [root@jarvis ~]# hostname
    jarvis

日拱一卒,功不唐捐!

喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址