A hostname is a human-friendly name given to a computer. It is a unique identifier that allows us to identify the machine in various network communications, making it easier to locate and manage devices.
Type:
hostname
To see where it is stored, type:
cat /etc/hostname
To get the hostname and additional information about your machine:
hostnamectl
To change the hostname, login as root user or use the sudo
command:
sudo hostnamectl set-hostname my-private-workstation
If you do not want to restart your terminal, you can force the current terminal to be changed by typing (assuming you use bash):
exec bash
Verify the hostname was changed:
cat /etc/hostname
Check the content of the /cat/hosts
file
cat /etc/hosts
Even though the hostnamectl
command allows us to set the new hostname, it does not update the /etc/hosts
file. This is optional, but highly recommended.
To update the /etc/hosts
file, use the vim
command:
sudo vim /etc/hosts/
To ping this instance, run:
ping my-private-laptop