Details of the hostname modification method in Linux

  • 2020-05-27 07:55:12
  • OfStack

The hostname of the Linux operating system is an kernel variable and can be viewed in one of two ways


# hostname

and


# cat /proc/sys/kernel/hostname

Temporary modification of hostname

hostname of the system can be set through the hostname command


# hostname newname

newname is the new hostname to set, which takes effect immediately after running, but the changes are lost when the system is restarted.

Modify hostname permanently
Permanently changing the hostname of your system requires you to modify the relevant setup files

1 linux system based on the RedHat distribution

Modify the /etc/sysconfig/network file, and change the inside HOSTNAME line to HOSTNAME=NEWNAME, where NEWNAME is the hostname to be set.

2. linux system based on Debian distribution

Change the content of the configuration file /etc/hostname to NEWNAME, where NEWNAME is the hostname to be set.
After you fix the configuration file, restart the system and the configuration file will be read to set the new hostname.
Note :/etc/hosts is not directly related to the setting of hostname, only the /etc/hosts file is used when you want to access it from the new hostname on the local machine. There is no necessary connection between the two.


Related articles: