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.
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 ~]#
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 ~]$
Create a dev user.
command
useradd -m dev
Execution example
[root@tspdev01 ~]# useradd -m dev
[root@tspdev01 ~]#
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 ~]#
Switch from the root user to the dev user.
command
su - dev
Execution example
[root@tspdev01 ~]# su - dev
[dev@tspdev01 ~]$
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. ** **
** ○ 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.
Variable HOSTNAME 6.3. Hostname configuration using HOSTNAMECTL Actually easy! How to create and add Linux users
Recommended Posts