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 <hostname> returns the full hostname:

$ hostname
> jvf-imac
$ hostname -f
> jvf-imac
$ hostname -s
> jvf-imac
$ host jvf-imac                                                                                                                                                                                     
> jvf-imac.fritz.box has address

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?


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

DNS Setup (shortened)

$ scutil --dns                                                                                                                                                                                          
resolver #1
  search domain[0] : fritz.box
  nameserver[0] :
  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] :
  if_index : 4 (en0)
  flags    : Scoped, Request A records
  reach    : Reachable,Directly Reachable Address
  • 1
    In System Preferences > Sharing, what does t say the computer name is? I believe hostname gets the FQDN from there on OS X, whereas host <hostname> appears to query DNS (though I'm on 10.11…) – forquare Aug 29 '15 at 19:14
  • Forgive me, why is this helpful? The local machine name only gets an IP if connected to the network. The 'hostname' command is local, the 'host' command is network-based. Once you know the hostname you can ask DNS to resolve it for you. – agentroadkill Aug 29 '15 at 19:56
  • I agree with agentroadkill, I don't see how this is useful to my question, which is not about changing the hostname but to get the commandline tool hostname to display the correct, full hostname including domain information. The part about the output of the host tool was only to show that my network setup and DNS seems to be working correctly otherwise... – jvf Aug 31 '15 at 9:31
  • @jvf Please add your system version. I can't replicate the behavior of your system in Yosemite though I've enabled the (proxy-)dns setup of your Fritz!Box. – klanomath Aug 31 '15 at 9:39
  • Mac OS X 10.10.5, newest Yosemite version – jvf Aug 31 '15 at 10:53

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.

  • Though the scutil part is an answer I would have given also as a work-around the second part is doubtful. Fritz!Box is a (german) home router which provides a DHCP and a (proxy-)DNS-server. The standard domain name is fritz.box. Yesterday I setup a VM only connected to this router and I had no problems to get the fqdn of the Mac (=iMac.fritz.box) with hostname. – klanomath Aug 31 '15 at 9:50
  • @klanomath You are certainly right if the end problem is really how to make some fritz.box service work, but you can set your host name to be whatever you want whether or not it resolves or matches what the rest of the world expects :-) However, unless the OP does the work to explain how they really want a larger question answered - perhaps leaving that for a new thread works? As you commented, the details from the OP are lacking for us to dig into the deeper question at the moment. – bmike Aug 31 '15 at 9:54
  • Thanks for the answers and help so far. Setting the hostname with scutil works as a workaround. Of course I would be interested in finding a more general solution. Quite possible that the problem involves the dns proxy of the fritzbox. I'm happy to provide any additional info needed. If it is indeed the case, that fritzbox is the culprit here I'm also happy to change the original question to reflect this! – jvf Aug 31 '15 at 11:14
  • @jvf I'd say start a new thread if you want to add more details. :). Simpler that way for everyone – bmike Aug 31 '15 at 11:32
  • What DNS servers do you have configured? Can you list them? – Allan Aug 31 '15 at 15:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .