DEV Community

Cover image for Basic Linux command (Hostname)
Cheulong Sear
Cheulong Sear

Posted on

Basic Linux command (Hostname)

Hostname is used to display the system's DNS name, and to display or set its hostname or NIS domain name.

Hostname help you:

  • recognize machine
  • know when run commands against the machine
# to show the name of your computer
hostname

----
master-node
Enter fullscreen mode Exit fullscreen mode

Hostname is stored in /etc/hostname

cat /etc/hostname

----
master-node
Enter fullscreen mode Exit fullscreen mode

Hostname need to be existed in /etc/hosts as well.

Other commands

hostname -f # full name
hostname -I # show the machine IP on the system
Enter fullscreen mode Exit fullscreen mode
hostnamectl

----
Static hostname: master-node
...
Enter fullscreen mode Exit fullscreen mode

Change hostname

sudo hostnamectl set-hostname <new-hostname>

# update hosts
sudo nano /etc/hosts

----
127.0.0.1 localhost
127.0.1.1 <new-hostname> <shorten-version>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)