CentOS7 set hostname, hosts (permanent change)

1. Set the hostname

method 1:

centos7 which modify the way hostname change, modify / etc / hosts and / etc / sysconfig / network two files can no longer take effect. The new command is: 

[root@hadoop1 mort]# hostnamectl set-hostname hadoop101.com
[root@hadoop1 mort]# hostname -f
hadoop101.com

Method 2:

Modify the configuration file / etc / hostname to achieve modify the host name. Replace the contents of the file hostname name in the name of the host name you want to restart.

[root@hadoop1 mort]# vim /etc/hostname
hadoop101.com

Centos7 previous version please use this method:

[root@hadoop1 mort]# vi /etc/sysconfig/network
#Created by anaconda
NETWORKING=yes
GATEWAY=192.168.1.2
HOSTNAME=hadoop101.com

2. Set the / etc / hosts

[root@hadoop1 mort]# vi /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.1.100 hadoop100.com hadoop100
192.168.1.101 hadoop101.com hadoop101
192.168.1.102 hadoop102.com hadoop102
192.168.1.103 hadoop103.com hadoop103
192.168.1.104 hadoop104.com hadoop104
192.168.1.105 hadoop105.com hadoop105
192.168.1.106 hadoop106.com hadoop106

3. After the restart to take effect

Guess you like

Origin www.cnblogs.com/MWCloud/p/11346867.html