linux command line: find a host's canonical hostname

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.


Use dig(1). For normal lookups use:

dig full.hostname.xxx

and for reverse lookups use:

dig -x 127.0.0.1

Also check the man page for much more cool options.


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.