1、不想重启系统,修改方式方式
# oa 比如修改叫做oa
[root@tetets ~]# hostnamectl set-hostname oa
[root@tetets ~]# systemctl restart systemd-hostnamed
[root@tetets ~]# hostname
oa
重新开启终端就可以看到新的主机名了
2、修改配置文件
centos7:
主机名保存在/etc/hostname文件里,手动动编辑主机名:
sudo vi /etc/hostname
把旧的主机名删除,替换为新的主机名,保存文件就行了。要注意大小写。
不过,修改配置文件的方法,需要重启后生效,即reboot