(available) Centos modify hostname (permanent modification)

After reading a lot of technical articles, when it comes to Centos modifying HOSTNAME, there are usually a few answers:

 

(1) Temporary modification

         Direct hostname XXX and then start a new session, it will take effect, but after restarting, the hostname will return to its original state.

 

 (2) Permanent changes, mainly two files

         vim /etc/sysconfig/network then modify HOSTNAME= XXX

         vim /etc/hosts Then find 127.0.0.1, look at the corresponding host name, modify it to XXX

         

         Then, just restart.

  

   After changing to another name, it can indeed take effect.

 

   But if you just want to use localhost as the host name, it may not take effect if you change the host name in /etc/sysconfig/network to localhost, it may be the host name of 4WAN_1LAN_IPSec_VPN_Router.

 

then what should we do? Generally speaking, after modifying the hostname to localhost in /etc/sysconfig/network, add the hostname of the boot-up automatic execution to localhost in /etc/rc.localhost, that is, adding hostname localhost .

 

   ==============================================================================

 

   hostname is a kernel parameter under Linux system, it is saved under /proc/sys/kernel/hostname, but its value is read from /etc/rc.d/rc.sysinit when Linux starts.

    Hostname is a kernel parameter which stores hostname of the system. Its location is"/proc/sys/kernel/hostname" The value for this parameter is loaded to kernel by rc.sysinit file during the boot process.

 

 Conclusion: (1) /etc/sysconfig/network is indeed the configuration file of hostname. The value of hostname has a certain relationship with HOSTNAME in the configuration file, but there is no necessary relationship. The value of hostname comes from the kernel parameter /etc/proc/ kernel/hostname. If the kernel parameters are forcibly modified through the command, sysctl kernel.hostname=TEST modifies the kernel parameters, and the host name has been modified to TEST. But the value in /etc/sysconfig/network has not changed, so the kernel parameters are the dominant ones.

         (2) Does hostname have anything to do with the configuration under /etc/hosts? The answer is: the hostname has nothing to do with this configuration file, that is, modifying the hostname does not depend on the /etc/hosts file. In fact, the role of /etc/hosts is equivalent to DNS, providing the correspondence between IP addresses and hostnames. For example, after 127.0.0.1 is defined here to correspond to localhost, the IP address of 127.0.0.1 is the same as the domain name localhost and points to 127.0.0.1  

 

 

 

       

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

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