CentOS change hostname

The correct way to modify the hostname of centos

1 Modify hostname under centos6

copy code

[root@centos6 ~]$ hostname # View the current hostnmae
centos6.magedu.com
[root@centos6 ~]$ vim /etc/sysconfig/network # Edit the network file to modify the hostname line (restart takes effect)
[root@centos6 ~]$ cat /etc/sysconfig/network # Check for modifications
NETWORKING=yes
HOSTNAME=centos66.magedu.com
[root@centos6 ~]$ hostname centos66.magedu.com # Set the current hostname (effective immediately)
[root@centos6 ~]$ vim /etc/hosts # Edit the hosts file and add hostname to 127.0.0.1
[root@centos6 ~]$ cat /etc/hosts # Check
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 centos66.magedu.com
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

copy code

2 centos7 modify hostname

copy code

[root@centos7 ~]$ hostnamectl set-hostname centos77.magedu.com # Using this command will take effect immediately and restart will also take effect
[root@centos7 ~]$ hostname # Check it out
centos77.magedu.com
[root@centos7 ~]$ vim /etc/hosts # Edit the hosts file and add hostname to 127.0.0.1
[root@centos7 ~]$ cat /etc/hosts # Check
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 centos77.magedu.com
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

copy code

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325755877&siteId=291194637