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

Share:
7,058

Related videos on Youtube

MacGyver
Author by

MacGyver

Updated on September 18, 2022

Comments

  • MacGyver
    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
      Admin over 7 years
      Note 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 that hostname --fqdn doesn't bear much relation to hostname.
  • HBruijn
    HBruijn over 7 years
    See this for some more background: serverfault.com/a/331942/37681