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


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.)

2 Answers 2


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

$ facter domain
$ facter hostname
$ facter fqdn

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
  • Ah heck! that link to the Facter source code is no long valid. Sep 6, 2017 at 6:34

Probably because your system is part of a domain network that assigns a domain name. For example in my case, my router resolves all hostnames in the form of host.lan, "lan" being my domain, and "host" the name of my system.

The FQDN most likely comes from your router DNS, just run whatever you like of these commands:

nslookup your-ip-here
dig -x your-ip-here
host your-ip-here

An example using dig:

dig @ -x

; <<>> DiG 9.9.5-4-Debian <<>> @ -x
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11384
;; flags: qr aa rd ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

; EDNS: version: 0, flags:; udp: 4096
;     IN  PTR

;; ADDITIONAL SECTION:  86400   IN  PTR dsldevice.lan.

;; Query time: 2181 msec
;; WHEN: Thu Jun 19 20:01:32 AST 2014
;; MSG SIZE  rcvd: 77

Since I use my own DNS and not the router's I have to set the domain to query in the @ part. I'm querying the routers' own domain name.

You will find that it will return the domain name as your DNS/router sees you. There are various ways to disable this in the router, but I've found that the most easier way is just using other DNS.

  • It actually doesn't do a DNS lookup at all, so this answer is wrong. See Naftuli Tzvi Kay's answer with my edit.
    – jordanm
    Jun 20, 2014 at 0:31
  • Actually, it looks like dnsdomainname can do a lookup if your own host is not in /etc/hosts.
    – jordanm
    Jun 20, 2014 at 0:33
  • @jordanm so, it's not wrong?
    – Braiam
    Jun 20, 2014 at 0:37
  • Well, in OP's particular context it is, but it could be correct for some users. The OP said dnsdomainname did not return the domain name which is the only link in the chain that could do the dns lookup.
    – jordanm
    Jun 20, 2014 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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