Determine FQDN when hostname doesn’t give it

hostnamepuppet

In another question, I found that Puppet was generating certificates for my machine's FQDN but not the simple host name. In that example, kungfumaster was the hostname and was the value retrieved by running hostname. Puppet was generating certificates which specified the FQDN kungfumaster.domain.com.

How did Puppet determine that this was my FQDN? I have tried all of the following and not seen anything matching *.domain.com:

$ hostname -a && hostname -d && hostname --domain && hostname -f && \ 
    hostname --fqdn && hostname -A && hostname --long

kungfumaster
kungfumaster
kungfumaster 
kungfumaster

How can I get kungfumaster.domain.com from Bash? I've noticed that domain.com does in fact exist in /etc/resolv.conf, but I haven't been able to find it anywhere else.

I basically want to get the FQDN of the current machine as a string. The other solutions here on unix.se haven't worked for me. (ie: dnsdomainname, domainname, etc.)

Best Answer

It appears that under-the-hood, Puppet uses Facter to evaluate the domain names:

$ facter domain
domain.com
$ facter hostname
kungfumaster
$ facter fqdn
kungfumaster.domain.com

The answer is in the relevant Facter source code.

It does the following in order and uses the first one that appears to contain a domain name:

  1. hostname -f
  2. dnsdomainname
  3. parsing resolv.conf for a "domain" or "search" entry
Related Question