Basic Linux command (Hostname)
Cheulong Sear

Cheulong Sear @cheulong

About: Hi, I’m Cheulong Sear. Love learning new staff. I will show my journey in the IT field and what I'm building during my free time.

Location:
Bangkok, Thailand
Joined:
Jun 30, 2024

Basic Linux command (Hostname)

Publish Date: Jul 3
1 0

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

Comments 0 total

    Add comment