Ubuntu 主机名存放在 /etc/hostname 文件中
vim /etc/hostname
Fedora 主机名存放在 /etc/sysconfig/network 文件中
vim /etc/sysconfig/network
/etc/hosts
修改主机名为www
1.永久性更改:vim /etc/sysconfig/network
# Created by cloud-init on instance boot automatically, do not edit.
NETWORKING=yes
HOSTNAME=www
使用 hostnamectl status 来查看主机名的状态:
[root@VM_0_11_centos ~]# hostnamectl status
Static hostname: VM_0_11_centos
Icon name: computer-vm
Chassis: vm
Machine ID: 0ea734564f9a4e2881b866b82d679dfc
Boot ID: 1180627a6ff343f8b6a2622724cb1e5b
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-957.21.3.el7.x86_64
Architecture: x86-64
[root@VM_0_11_centos ~]# hostnamectl status --static
VM_0_11_centos
[root@VM_0_11_centos ~]# hostnamectl status --transient
VM_0_11_centos
[root@VM_0_11_centos ~]# hostnamectl status --pretty
VM_0_11_centos
cetos7需要用以下方式永久设置hostname
[root@VM_0_11_centos ~]# hostnamectl --static set-hostname "michael"
2.临时性更改 echo michael >/proc/sys/kernel/hostname
3.临时性更改 sysctl kernel.hostname=michael
4.临时性更改 hostname michael