Centos 6.x
vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
GATEWAY=192.168.10.1
vi /etc/hosts 127.0.0.1
localhost localhost.localdomain server
Centos 7.x
[root@localhost log]# hostnamectl status
Static hostname: localhost.yvsy7
Icon name: computer-vm
Chassis: vm
Machine ID: 68a9a20de8ab4776a88eff33bd41b8ae
Boot ID: 405ba16753364bad82f4d057a51b6499
Virtualization: microsoft
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-123.el7.x86_64
Architecture: x86_64
# 查看主机名
hostnamectl --static # 静态
hostnamectl --transient #瞬态
hostnamectl --pretty #灵活
# 设置主机名
hostnamectl set-hostname server #同时修改三种状态主机名
hostnamectl --static set-hostname server #永久修改主机名
文章评论
我就是随便看看