centos7和centos6修改主机名(永久生效那种)

版权声明:Don't trouble trouble until trouble troubles you. https://blog.csdn.net/JOJOY_tester/article/details/85937284

一、centos6.8为例:

1.编辑/etc/sysconfig/network文件,修改hostname项:

#vim /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=vpc-xxx-01    #(新主机名)

NETWORKING_IPV6=no

PEERNTP=no

GATEWAY=192.168.5.222

2.还有一个修改是:绑定IP+hostname /etc/hosts

# vim /etc/hosts

127.0.0.1 localhost

192.168.0.0    vpc-xxx-01        #(新主机名)

3.主机名修改需要reboot

二、centos7.4为例

1、方法一使用hostnamectl命令

hostnamectl set-newhostname 自己想要的名字

2、方法二:centos7修改主机名是编辑/etc/hostname 文件

echo 'newhostname' > /etc/hostname

当然还有其他方法。

猜你喜欢

转载自blog.csdn.net/JOJOY_tester/article/details/85937284