Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As per the this question's title, hostname doesn't return domain info and domainname returns empty. I want to find out the full machine and domain for the machine I'm using (Mac OS X 10.5.8). How can I go about doing this? Tks.

share|improve this question

Probably you don't have a domain defined right now

share|improve this answer
Thanks for the prompt reply Dominik. I haven't got a hand in the network itself but is there anything I can do as a client to get that domain to set itself? – Anonymous Mar 18 '10 at 19:30
Did you get your IP by DHCP ? – Dominik Mar 18 '10 at 19:31
Yeap. IP is auto-assigned via DHCP. If I do a DNS lookup using $ host hostname it does show me the full domain. – Anonymous Mar 18 '10 at 19:36
In that last comment it hostname should be wrapped in backticks. – Anonymous Mar 18 '10 at 19:48
host `hostname`

will have what you are looking for. To extract just the fully qualified domain name

host `hostname` | sed 's/\([^ ]*\)\ .*/\1/'

Of course; this only really works if you've applied the AlwaysAppendSearchDomains fix to mDNSResponder. In some cases, for example you are behind a VPN, no amount of coaxing that I've found will give you the domain name if the infrastructure has not been able to set it for you.

share|improve this answer

Your Answer


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