[Linux] Why do I, an infrastructure engineer, not use the "hostname" command?

Introduction

I would like to write about the reason why I basically do not use the "hostname" command because I have experience from Linux operation monitoring to design and construction.

Target OS this time

Linux OS in general (RHEL / CentOS / Solaris, etc.)

What is the "hostname" command in the first place?

This command confirms the host name of the Linux OS.

The usage is like this.

hostname


[root@GitBucket-sv ~]# hostname
GitBucket-sv
[root@GitBucket-sv ~]#

In this way, it is a command that can confirm the host name.

For details, please see the explanation on this site. [Hostage] command-display / set the host name

Why not use it basically?

** This is because the host name may be changed due to incorrect input. ** **

Here is an example of incorrect input.

typo


[Command input]
[root@GitBucket-sv ~]# hostname i

[Host name confirmation]
[root@GitBucket-sv ~]# hostname
i
[root@GitBucket-sv ~]#

In this way, the host name itself will change. (In the above case, the host name is "i".)

By the way, hostname -i is a command to check the IP address of the server.

IP address confirmation


[root@GitBucket-sv ~]# hostname -i
fe80::250:56ff:fe8c:2091%ens192 2404:7a80:91a1:4d00:250:56ff:fe8c:2091%2 192.168.0.150
[root@GitBucket-sv ~]#

** In this way, it is possible to change the host name due to incorrect input, so basically it is not recommended to use it. ** **

Then, what command should be used to confirm the host name?

The ʻuname -n` command is recommended.

Here is an example of execution.

Execution example


[root@GitBucket-sv ~]# uname -n
GitBucket-sv
[root@GitBucket-sv ~]#

There is no problem if you make a mistake.

Example of incorrect input


[root@GitBucket-sv ~]# uname n
uname:Extra operator`n'
Try 'uname --help' for more information.
[root@GitBucket-sv ~]#

As you can see, the error is displayed.

If you want to know more about the ʻuname` command, please see the explanation on this site. uname command (displays OS or hardware information)

Summary

It is safe to refrain from using the hostname command when checking the host name. → There is a possibility that the host name will be changed by mistake.

When checking the host name, it is safer to check with the ʻuname -n` command. → There is no risk of changing the host name

Recommended Posts

[Linux] Why do I, an infrastructure engineer, not use the "hostname" command?
[Linux] How to use the echo command
How to use the Linux grep command
When the Linux command $ yum -y install gives an error (yum: command not found)
I want to use Linux commands at the command prompt! Use Linux commands at the command prompt instead of Git Bash
Linux user addition, how to use the useradd command
(Remember quickly) How to use the LINUX command line
I can't use the darknet command in Google Colaboratory!
[Linux] I tried to summarize the command of resource confirmation system
You should not use the --color = always option of the grep command
I summarized the sar command that Netflix performance engineers also use