Why does hostname --fqdn only return the domain name?

5,716

As it turns out, the culprit was /etc/resolv.conf. Changing:

search <myprovider>.at
nameserver ...
nameserver ...
nameserver ...

to

search <myname>.at <myprovider>.at
nameserver ...
nameserver ...
nameserver ...

fixes the issue.

(I'll leave the question open for the time being, just in case someone can come up with an explanation for this.)

Share:
5,716

Related videos on Youtube

Heinzi
Author by

Heinzi

Updated on September 18, 2022

Comments

  • Heinzi
    Heinzi over 1 year

    Relevant files (slightly anonymized):

    heinzi@d2:~$ cat /etc/hostname
    d2
    heinzi@d2:~$ cat /etc/hosts
    127.0.0.1       localhost
    <myexternalip>  d2.<myname>.at    <myname>.<myprovider>.at       <myname>
    
    # The following lines are desirable for IPv6 capable hosts
    ::1     localhost ip6-localhost ip6-loopback
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    

    This output is correct:

    heinzi@d2:~$ hostname
    d2
    heinzi@d2:~$ hostname --all-fqdns
    d2.<myname>.at
    

    But this I don't understand:

    heinzi@d2:~$ hostname --fqdn
    <myprovider>.at
    

    Shouldn't it be d2.<myname>.at, since that's the first entry after <myexternalip>? And if it's the second entry, shouldn't it by <myname>.<myprovider>.at instead of just the domain name?

    I'm aware that I could probably fix this by playing around with the hosts file, but I'd really like to understand why this happens. I read the hostname man page and googled and think that it should return d2.<myname>.at in my case. Thus, I'd really prefer an answer along the lines of "This is because ..." instead of "Try ... and see if it works.".

    The system is Debian 7.5 "wheezy".

    • Tony Anderson
      Tony Anderson about 10 years
      Instead of using <my name> use the words 'foo' and 'bar', it is easier to read.
    • Heinzi
      Heinzi about 10 years
      @spuder: Thanks, I'll keep that in mind for my next question.
    • Volker Siegel
      Volker Siegel over 9 years
      @spuder I see your point, but here, the term Name or Provider in the names are useful. Hmm... maybe you meant replacing <myname> not by foo, but by fooName? That's much better indeed.