Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

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 @10.0.0.1 -x 10.0.0.1

; <<>> DiG 9.9.5-4-Debian <<>> @10.0.0.1 -x 10.0.0.1
; (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

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;1.0.0.10.in-addr.arpa.     IN  PTR

;; ADDITIONAL SECTION:
1.0.0.10.in-addr.arpa.  86400   IN  PTR dsldevice.lan.

;; Query time: 2181 msec
;; SERVER: 10.0.0.1#53(10.0.0.1)
;; 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.

share|improve this answer
    
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 at 0:31
    
Actually, it looks like dnsdomainname can do a lookup if your own host is not in /etc/hosts. –  jordanm Jun 20 at 0:33
    
@jordanm so, it's not wrong? –  Braiam Jun 20 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 at 0:38
up vote 2 down vote accepted

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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