Getting hostname on CentOS 6.6 from command line
7,058
The DNS or NIS entries might be different. Clarify with your system administrator which name is being used. You may need to edit /etc/hostname
to make a change permanent.
# hostname
# cat /etc/hostname
# domainname
# dnsdomainname
Source: man hostname
Related videos on Youtube
Author by
MacGyver
Updated on September 18, 2022Comments
-
MacGyver over 1 year
In the command below, I'm trying to get the hostname of the server I'm logged into. Please note that I'm on the actual server and not ssh'ed into another server!! I'm trying to get the hostname. Our server administrator was telling me the hostname is
lvs-mcsec01
, but when I call the hostname command, I get something different. It looks like it's giving me the fully qualified domain name using the alias as the prefix, and not the hostname. How do I get the hostname using a Linux command?[root@test-sec01 ~]# hostname --fqdn test-sec01.atg.org [root@test-sec01 ~]# hostname -a [root@test-sec01 ~]#
-
Admin over 7 yearsNote that the server's own hostname has no real link to whatever in DNS (it should have, but there is nothing to enforce that -- only the desire for consistency). Also note that
hostname --fqdn
will be doing various DNS lookups. Try adding the-v
option and you'll see how its working out its answer. You may well find thathostname --fqdn
doesn't bear much relation tohostname
.
-
-
HBruijn over 7 yearsSee this for some more background: serverfault.com/a/331942/37681