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
日拱一卒,功不唐捐!