1 Modify hostname under centos6
[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
2 centos7 modify hostname
[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