Home>Article>Operation and Maintenance> What to do if centos hostname does not take effect
Solution to the problem that centos hostname does not take effect: 1. Modify the "/etc/sysconfig/network" and "/etc/hosts" files; 2. Permanently change the host name through the centos command.
The operating environment of this article: CentOS 7 system, Dell G3 computer.
centos hostname does not take effect?
Centos changes the hostname and it becomes invalid after restarting. Solution:
Display host name command:
[hadoop@localhost ~]$ hostname localhost.localdomain
Modification:
Mainly modify two files, one is /etc/sysconfig/network and the other is /etc/hosts
Modify to master. The key point is to add it to the first one when modifying the hosts file. The modification must be made by root. Other users do not have permission.
[root@master hadoop]# vim /etc/sysconfig/network [root@master hadoop]# cat /etc/sysconfig/network # Created by anaconda NETWORKING=yes HOSTNAME=master [root@master hadoop]# vim /etc/hosts [root@master hadoop]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 master ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.238.129 master 192.168.238.130 slave2 192.168.238.131 slave1 [root@master hadoop]#
The last and more important thing is to permanently change the host name. :
Method one:
centos7 command
[root@master ~]# hostnamectl set-hostname master
Method two:
Applicable to all
Modify directly file, restart after modification
[root@master ~]# vi /etc/hostname master ~ ~ ~ ~ :wq [root@master ~]# reboot
Recommended tutorial: "centos tutorial"
The above is the detailed content of What to do if centos hostname does not take effect. For more information, please follow other related articles on the PHP Chinese website!