Recently, I bought a virtual host and installed Ubuntu system, but the host name is not friendly.
root@c892484c3cdb:~#
For the perfect person, it’s annoying to see such an unrepresentative name.
How to change the host name ???
The answer is to use Linux hostname command.
About the hostname command
hostname – show or set the system’s host name
View current hostname
root@c892484c3cdb:~# hostname
c892484c3cdb
Modify hostname
root@c892484c3cdb:~# hostname ylspirit
Modify hostname, no need to restart, new session takes effect, restart los.
How to modify the hostname permanently ???
About the /etc/hostname file
This file stores the name of the hostname of the current host. Each time the system starts, it will get the name of the system by reading this file.
root@c892484c3cdb:~$ vim /etc/hostname
ubuntu-hostname
# save and reboot system
About the /etc/hosts file
Network host name.
You can redirect the IP pointed to by the domain name by modifying the hosts file
Query the interface IP corresponding to the host name:
root@ubuntu-hostname:~# hostname -i
127.0.1.1