" command; 3. Use "sudo hostname Home >
Article > Operation and Maintenance > How to change the host name in linux Method: 1. Open the "/etc/hostname" file, delete the old hostname, replace it with the new hostname, and save the file; 2. Use "sudo hostnamectl set-hostname " command; 3. Use the "sudo hostname The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer. First we use the hostname command to view the current host name. You can also use the hostnamctl command The host name is saved in Delete the old host name, replace it with the new host name, and save the file. Pay attention to capitalization. If you don't update the If you are changing the host name of the Linux server, the new host name should be resolved to the public IP of the Linux server. If you change the hostname of your PC, the new hostname should resolve to 127.0.0.1, or 127.0.1.1. 127.0.1.1 is the IP of the local host resolved by the Debian Linux distribution. When the Debian system is installed, if the computer's IP is dynamic, the Debian installation program will create the 127.0.1.1 The command syntax is: This command will delete the host name in the /etc/hostname file and then replace it with the new host name . Like the first method, we also need to update the /etc/hosts file. The essence of both methods is the same. If you only need to temporarily change the host name, you can use the hostname command. This command will not change the static hostname (static hostname) in the /etc/hostname file, it only changes the temporary hostname (transient hostname). So after restarting the computer it will go back to the old hostname. Static hostnames are saved in the Related recommendations: "Linux Video Tutorial" The above is the detailed content of How to change the host name in linux. For more information, please follow other related articles on the PHP Chinese website!How to change the host name in linux
View the current host name
hostname
hostnamectl
Method 1: Modify the configuration file
/etc/ hostname
file, so we can open this file and manually edit the hostname. sudo nano /etc/hosts
/etc/hosts
file, then some programs, such as sudo, don't know how to resolve the new hostname. Method 2: hostnamectl command
sudo hostnamectl set-hostname <newhostname>
Method 3: Hostname command to make temporary changes
sudo hostname <new-hostname>
/etc/hostname
file.