I received such a question in a previous article.
** [Previous article] ** [Linux] Why do I, an infrastructure engineer, not use the "hostname" command?
I'm sorry, but I didn't consider the FQDN. (Because there was no situation to check the FQDN in business.)
It's a big deal, so I'll try to verify it.
OS version
[root@tspdev01 ~]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
[root@tspdev01 ~]#
/ etc / hostname
like this in advance.hostname
[root@tspdev01 ~]# cat /etc/hostname
tspdev01.example.com
[root@tspdev01 ~]#
However, this time I would like to do it as a root user for verification.
Execution command
hostname -f
Execution result
[root@tspdev01 ~]# hostname -f
tspdev01.example.com
[root@tspdev01 ~]#
When you check the execution result, it is displayed with FQDN(tspdev01.example.com)
.
I would like to check the FQDN with another command.
Try running the command that matches your question.
Execution command
echo `uname -n`.`dnsdomainname`
The execution result looks like this.
Execution result
[root@tspdev01 ~]# echo `uname -n`.`dnsdomainname`
tspdev01.example.com.example.com
[root@tspdev01 ~]#
As a result, the domain is displayed twice.
Execute with this command
Execution command
uname -n
The execution result is here.
Execution result
[root@tspdev01 ~]# uname -n
tspdev01.example.com
[root@tspdev01 ~]#
It was displayed by FQDN!
Execution command
hostname -s
The execution result is here.
Execution result
[root@tspdev01 ~]# hostname -s
tspdev01
[root@tspdev01 ~]#
Only the abbreviated system of the host name is displayed.
Execution command
uname -n | awk -F "." '{print $1}'
The execution result is here.
Execution result
[root@tspdev01 ~]# uname -n | awk -F "." '{print $1}'
tspdev01
[root@tspdev01 ~]#
In this way, only the shortened host name can be displayed.
.
in tspdev01.example.com
.** Reference article ** How to specify the delimiter with awk's -F option
Execution command
hostname -d
The execution result is here.
Execution result
[root@tspdev01 ~]# hostname -d
example.com
[root@tspdev01 ~]#
Execution command
echo `dnsdomainname`
The execution result is here.
Execution result
[root@tspdev01 ~]# echo `dnsdomainname`
example.com
[root@tspdev01 ~]#
Only the domain name is displayed.
** Display method by FQDN **
uname -n
** Show only abbreviated host name **
uname -n | awk -F "." '{print $1}'
** Show domain name only **
echo `dnsdomainname`
Perhaps there are other ways. I haven't studied enough yet, so I will continue to catch up.
Recommended Posts