Thanks for your detailed explanation, @simos. Many a mickle makes a muckle. Here’s my mickle on how to modify the hostname of the Ubuntu OS (>=18.04?):
sudo hostnamectl set-hostname NEW_NAME
-
sudo vim /etc/hosts
(Update the hostname manually here as 1. cannot do it.); -
exec $SHELL
(Update the prompt immediately without rebooting).
My story: I once ran across the problem that after updating the hostname, bash/zsh responded very slowly. At last, I found out that it was caused by file /etc/hosts was not updated automatically and accordingly. The OS might be confused about resolving itself, not knowing who is who.