Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

what is the easiest way to get a host's canonical host name from linux's command line?

If it matters, my shell is bash.

CLARIFICATION: I want another host's canonical hostname, either by ip or by non canonical hostname. Not the local host's canonical hostname.

share|improve this question

7 Answers 7

Use dig(1). For normal lookups use:


and for reverse lookups use:

dig -x

Also check the man page for much more cool options.

share|improve this answer

A remote host's node name bears no necessary relationship to any of its network names. You'll have to log in and use the hostname command.

If you're looking for the Fully Qualified Domain Name (FQDN) of a network address, you can use DNS query tools like dig or nslookup, as described by @firm and @Richard Holloway.

share|improve this answer

You could use also the host command. Like in this example


The result will be something like domain name pointer
share|improve this answer

To find the fqdn of a remote host with IP you can use


and see the answer contains

name =
share|improve this answer

To be clear, hostname will just return the short name. Use the -f parameter; hostname -f to get the fully qualified name.

share|improve this answer

There is no "reverse lookup" for canonical names. That is: given an A record, there is no way to get a listing of what CNAME records point to it.

share|improve this answer

Here's the command:


share|improve this answer
I want another host's canonical hostname, either by ip or by non canonical hostname. I should have clarified that. – flybywire Mar 16 '10 at 8:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.