Excellent software and practical tutorials
Linux server host name modification
When using cloud servers from major vendors, newly created instances will automatically generate a host name with a string of characters, which is very inconvenient for daily use. Is there any way to modify the host name after root@? You can modify it with a command.
First pass hostname View the cloud server host name
We can see a long string of host names: ip-172-31-24-219.ap-southeast-1.compute.internal
howModify the host name, customize it to the name you need.
The Centos system can be directly run through the command hostnamectl set-hostname hostname Make the changes and log in to the shell again after the changes are complete.
Temporarily change the host name
pass hostname To modify, enter the command hostname, and re-login to Xshell to take effect. This command is used to temporarily modify the Linux host name. Its survival time is the current Linux running time, that is, the running time before the next restart. Generally, the modification takes effect immediately, but this is only temporary, not permanent, and will be restored after restarting the system.
Permanently change the hostname
By modifying the configuration file
vi /etc/sysconfig/network
At the bottom of this configuration file, add a line. First, press i to open vi editing mode. Then add the following line at the bottom:
HOSTNAME=Hostname
After adding, press ESC to exit the edit mode, then enter :wq Save and exit!
This modification can permanently modify the hostname of the Linux server, but it will not take effect immediately. You need to restart the system to take effect. By modifying this configuration file and using the hostname command, you can immediately and permanently modify the hostname of the Linux server.Temporarily change the host nameAfter editing the network file, use reboot to restart the server.
After restarting, log in to the server and you will find that the host name after root@ has been changed. Also use the following command to view the content of the network.
cat /etc/sysconfig/network
If it is Ubuntu system, you need to modify the file /etc/hostname, change the corresponding host name to the new host name.
Finally, you need to /etc/hosts Replace the old host name corresponding to 127.0.0.1 with the new host name. Use the command hostnamectl set-hostname hostnameRevise.