Make `hostname -f` return fully qualified hostname How can i make hostname (i.e. the unix commandline tool hostname, invoked in terminal) return a hostname including the domain information?

At the moment, hostname, hostname -f and hostname -s return the same name, all without the domain information, but host &lt;hostname&gt; returns the full hostname:

$ hostname
&gt; jvf-imac
$ hostname -f
&gt; jvf-imac
$ hostname -s
&gt; jvf-imac
$ host jvf-imac                                                                                                                                                                                     
&gt; jvf-imac.fritz.box has address 192.168.178.31


The question is not about how I can get the full hostname in general. Some scripts I use rely on hostname -f to get the fully qualified hostname, so I need to make hostname -f return the correct hostname. Anyone any idea?

Updates

System Overview


System Version: OS X 10.10.5 (14F27)
Kernel Version: Darwin 14.5.0
Computer Name: jvf_imac


Content of resolv.conf (shortened)

domain fritz.box
nameserver 192.168.178.1


DNS Setup (shortened)

$ scutil --dns                                                                                                                                                                                          
resolver #1
  search domain[0] : fritz.box
  nameserver[0] : 192.168.178.1
  if_index : 4 (en0)
  flags    : Request A records
  reach    : Reachable,Directly Reachable Address

resolver #2
  domain   : local
  options  : mdns
  timeout  : 5
  flags    : Request A records
  order    : 300000

resolver #3
  domain   : 254.169.in-addr.arpa ...

...

resolver #7
  domain   : b.e.f.ip6.arpa ...

DNS configuration (for scoped queries)

resolver #1
  search domain[0] : fritz.box
  nameserver[0] : 192.168.178.1
  if_index : 4 (en0)
  flags    : Scoped, Request A records
  reach    : Reachable,Directly Reachable Address
OS X is different in this case in that it might change your settings when it gets a response from your router / DNS+DHCP. 

If you aren't getting a FQDN out of hostname, you couod set a FQDN first.

The Mac tool is scutil

scutil --get HostName            # same as hostname
scutil --get LocalHostName       # same as hostname -s
scutil --get ComputerName


If you want jvf-imac.fritz.box then simply:

sudo scutil --set HostName jvf-imac.fritz.box


You could set the host name with sudo hostname ... as well and it wouldn't be wrong. If I were to guess, you probably have fritz.box in /etc/resolv.conf which is why the DNS lookup appends the domain name since you didn't specify one more fully.