1.查看當前的主機名
[root@localhost datas]# hostname localhost [root@localhost datas]# hostnamectl Static hostname: localhost.localdomain Transient hostname: localhost Icon name: computer-vm Chassis: vm Machine ID: f1d9ecb6c6bd4e02b58e19bba402056c Boot ID: 91603e0798814b54a928e70fd2a2754f Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-693.el7.x86_64 Architecture: x86-64
2.臨時修改主機名
[root@localhost datas]# hostname yin 臨時修改,重啟服務器后就不生效了 [root@localhost datas]# hostname yin [root@localhost datas]# hostname -i 查看本機器名對應的ip地址 fe80::20c:29ff:fe5f:6d17%ens33 192.168.75.205
3.永久修改主機名
需要修改以下兩個配置文件
1、方法一使用hostnamectl命令 [root@xlucas1 ~]# hostnamectl set-hostname xlucas2 2、方法二:修改配置文件 /etc/hostname 保存退出 [root@xlucas1 ~]# vi /etc/hostname xlucas2