1. What is Ubuntu host name
When you log in to Ubuntu after you export your account password, you will see a line prompt
[email protected]~$
The ' Wang ' before the ' @ ' sign is your account name; After the ' @ ' sign, ': ' Before ' Ubuntu ' is the hostname
Use the hostname command to view the host name
[Email protected]:~$ hostname
Ubuntu
2. Temporarily modify host name
Use the hostname command to temporarily modify the hostname and fail after reboot
[Email protected]:~$ sudo hostname UBUNTU
[sudo] password for Wang:
[Email protected]:~$ hostname
Ubuntu
You will find that the host name viewed with hostname has been changed from "Ubuntu" to "Ubuntu" in uppercase. However, the host name in the prompt does not change, use the Exit command to exit the current account, and then log back in, and you will find
[email protected]: ~$
The host name in this prompt has been "UBUNTU" in uppercase
When you restart the computer, you will find the prompt back to the lowercase ' ubuntu ', using the hostname command to view the host name when the actual is also lowercase ' ubuntu '
[Email protected]:~$ hostname
Ubuntu
3. Permanently modify the host name
You need to modify the '/etc/hostname ' and '/etc/hosts ' files if you want to modify the host name to take effect permanently
Check out these two files with the cat command first
[Email protected]:~$ cat/etc/hostname
Ubuntu
[Email protected]:~$ cat/etc/hosts
127.0.0.1 localhost
127.0.1.1 Ubuntu
# The following lines is desirable for IPV6 capable hosts
:: 1 localhost ip6-localhost ip6-loopback
Ff02::1 Ip6-allnodes
Ff02::2 ip6-allrouters
Only the host name is saved in the '/etc/hostname ' file; the second line in the '/etc/hosts ' file is followed by the hostname. After the two host names are modified, restart the computer to complete a permanent modification of the host name.
Use the VIM command to modify the '/etc/hostname ' and '/etc/hosts ' files
[Email protected]:~$ sudo vim/etc/hostname
[Email protected]:~$ sudo vim/etc/hosts
The modified file should look like this, using the cat command to view
[Email protected]:~$ cat/etc/hostname
Ubuntu
[Email protected]:~$ cat/etc/hosts
127.0.0.1 localhost
127.0.1.1 UBUNTU
# The following lines is desirable for IPV6 capable hosts
:: 1 localhost ip6-localhost ip6-loopback
Ff02::1 Ip6-allnodes
Ff02::2 ip6-allrouters
Restart the computer at this point, you can find that the host name in the prompt has become uppercase ' Ubuntu ', using the hostname command to view the host name has also become uppercase ' Ubuntu '
Modified successfully:)
Modify Ubuntu host Name