linux command line: find a host's canonical hostname

51,477

Solution 1

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.

Solution 2

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.

Solution 3

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

Solution 4

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

host xxx.xxx.xxx.xyz

The result will be something like

xyz.xxx.xxx.xxx.in-addr.arpa domain name pointer name.domain.com

Solution 5

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:
51,477

Related videos on Youtube

flybywire
Author by

flybywire

Updated on September 17, 2022

Comments

  • flybywire
    flybywire almost 2 years

    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.

  • flybywire
    flybywire over 14 years
    I want another host's canonical hostname, either by ip or by non canonical hostname. I should have clarified that.