What to do if centos hostname does not take effect

藏色散人
Release: 2022-01-17 10:55:51
Original
4237 people have browsed it

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.

What to do if centos hostname does not take effect

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
Copy after login

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]#
Copy after login

The last and more important thing is to permanently change the host name. :

Method one:

centos7 command

[root@master ~]# hostnamectl set-hostname master
Copy after login

Method two:

Applicable to all

Modify directly file, restart after modification

[root@master ~]# vi /etc/hostname 
master
~                                  
~                                   
~                                        
~                             
 
:wq
[root@master ~]# reboot
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template