Setting the Hostname of Linux Workstation or Server
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
References:
Subscribe to my newsletter
Read articles from Karlygash Yakiyayeva directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Karlygash Yakiyayeva
Karlygash Yakiyayeva
Postgraduate in Communications Engineering with working experience in the Support Desk and self-study in software development.