[CENTOS] [Linux] What is the host name confirmation method other than the hostname command?

Introduction

When I posted an article like this the day before yesterday, thankfully the response was great. [Linux] Why do I, an infrastructure engineer, not use the "hostname" command?

In this article, I would like to introduce how to check the host name other than the hostname command on Linux.

How to check the host name other than the hostname command

uname -n

ʻUname` is a command that displays system information.

You can display the host name by adding the -n option to this command.

command


uname -n

Execution result


[root@tspdev01 ~]# uname -n
tspdev01
[root@tspdev01 ~]#

hostnamectl status

This is a host name confirmation command that can be used on Linux 7 series (RHEL / CentOS).

command


hostnamectl status

Execution result


[root@tspdev01 ~]# hostnamectl status
   Static hostname: tspdev01
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 4ac15a471f30914187be09916857cdb9
           Boot ID: bedcdc6861c34bc5881a2ddb91c7955c
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-1127.13.1.el7.x86_64
      Architecture: x86-64
[root@tspdev01 ~]#

echo $HOSTNAME

You can check the host name by checking the value of the variable HOSTNAME.

command


echo $HOSTNAME

Execution result


[root@tspdev01 ~]# echo $HOSTNAME
tspdev01
[root@tspdev01 ~]#

[Extra edition] Create a test user and execute "hostname i".

Let's verify if the host name is ʻi`.

The OS is here.

OS version


[dev@tspdev01 ~]$ cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
[dev@tspdev01 ~]$

1. User created

Create a dev user.

command


useradd -m dev

Execution example


[root@tspdev01 ~]# useradd -m dev
[root@tspdev01 ~]#

2. Set a password for the created user

Set a password for the dev user.

command


passwd dev

Execution example


[root@tspdev01 ~]# passwd dev
Change password for user dev.
new password:
Please re-enter your new password:
passwd:All authentication tokens have been successfully renewed.
[root@tspdev01 ~]#

3. Switch to dev user

Switch from the root user to the dev user.

command


su - dev

Execution example


[root@tspdev01 ~]# su - dev
[dev@tspdev01 ~]$

4. Execute hostname i.

Execution result


[dev@tspdev01 ~]$ hostname i
hostname: you must be root to change the host name
[dev@tspdev01 ~]$

** As a result, the root user was asked and could not be modified. ** **

Summary

** ○ Host name confirmation command other than the hostname command **

** ○ What happens if I enter hostname i as a general user? ** **

Root privileges were required and the host name could not be changed.

Reference article

Variable HOSTNAME 6.3. Hostname configuration using HOSTNAMECTL Actually easy! How to create and add Linux users

Recommended Posts

[Linux] What is the host name confirmation method other than the hostname command?
It's a Mac. What is the Linux command Linux?
What is Linux? [Command list]
What is the Linux kernel?
What is Linux
What is Linux?
What! The unzipped file name was SJIS! command?
(Linux beginner) What is the magic word aux?
What is Linux
What is Linux
What is the difference between Unix and Linux?
What is the true identity of Python's sort method "sort"? ??
What is Linux for?
What is UNIT-V Linux?
Get the class name where the method is defined in the decorator
Get the host name of the host PC with Docker on Linux
What is the activation function?
What is the interface for ...
What is the Callback function?
[Linux] I tried to summarize the command of resource confirmation system
What to do if the inode is exhausted on EC2 Linux
[Linux] What is the method to solve the package dependency error of yum and rpm in the actual workplace?