-1

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 ~]#
MacGyver
  • 1,864
  • 7
  • 37
  • 50
  • 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`. – Cameron Kerr Aug 04 '16 at 08:59

3 Answers3

1

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

durette
  • 164
  • 8
0

The only way your question makes sense is if your system administrator meant NetBIOS/Active Directory/WINS hostname, which requires samba service to be installed and running in order to be accessible.

Try nmblookup -A <your_ip_address> - it should display what windows-users see instead of your real hostname (which is indeed accessible via hostname --fqdn command)

Anubioz
  • 3,597
  • 17
  • 23
  • The good news is that I can find the server from Putty using either name (alias, which shows at the command prompt ... OR ... VServer hostname)... so the hostname from /etc/sysconfig/network from HBruijn's answer) appears to be a local setting (local hostname). Perhaps for certain RPMs installed on CentOS, maybe? – MacGyver Aug 03 '16 at 19:16
0

You use the hostname or uname command to get or set the hostname.

A server admin can set any hostname they want, which may be completely different from the name the system has in your inventory, your CMDB, the name it has for your hypervisor in case of a VPS, it can have many different forward DNS records and again even a different reverse DNS record for each of it's IP-addresses. Consistency in those is somewhat recommended but in no way required.

CentOS 6 sets the hostname at boot from /etc/sysconfig/network and will resolve the (external) ip-addresses by default from /etc/hosts

HBruijn
  • 72,524
  • 21
  • 127
  • 192
  • We're using VServer and we set our DNS entries using Info Blocks, if that means anything to you. I've never used either, but this is what they are telling me. When I look at that file (/etc/sysconfig/network), it has two lines: NETWORKING=yes ... and HOSTNAME=localhost.localdomain – MacGyver Aug 03 '16 at 19:06
  • 1
    See this for some more background: http://serverfault.com/a/331942/37681 – HBruijn Aug 03 '16 at 19:09