Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've recently bought myself one of the new mid-2011 Mac Minis with OS X Lion, I'm completely new to Mac OS but I've used linux quite a bit before. The problem I'm having is that at the terminal my hostname is displayed as (blanked some of the numbers out) this is basically "unknown-(ethernet mac addr)"

unknown-28-00-00-00-00-8f:~ michael$

In linux I would have just edited /etc/hostname but there doesn't seem to be a file for it. I've tried changing the computer name in:

System Preferences => Sharing => Computer Name

with no luck.

This is purely a cosmetic issue for me but something must of broken in the setup for my hostname to look like that!

share|improve this question
1  
I think this belongs in the Apple portion of SE (Stack Exchange) –  wizlog Aug 3 '11 at 13:46
    
Is your router/DHCP server/whatever assigning a dynamic DNS address for your machine? If so, the Mac might be defaulting to that as its hostname. –  Gordon Davisson Aug 3 '11 at 15:23
    
@wizlog: No, it doesn't. It is just fine here. –  Wuffers Aug 3 '11 at 18:48
    
@wizlog as we've explained to you before, our official policy is that if a question is on-topic for Super User - which questions about OS X are - then it stays on Super User. –  nhinkle Aug 3 '11 at 18:53

5 Answers 5

I had this same hostname issue after reformatting a server Mac with OS X Lion. The hostname that kept showing in Terminal was not the same as the DNS hostname for the IP address obtained from DHCP. I tried "sudo hostname [hostname]" and it appeared to work, but after a reboot it would revert again.

After doing "scutil --set HostName "FQDN"" it permanently set the hostname in Terminal. I am still showing an obscure name in DHCP lease for that IP address, which is linked to the computer's share name. Go into system preferences > Sharing and edit the computer name and description to update correct hostname as seen through DHCP leases.

Editing host or text/config files is not necessary and not recommended.

share|improve this answer

I added the following

127.0.0.1       _your_host_name

to the /etc/hosts file, and it works fine.

Before

/Users/apillai>ssh macair
ssh: Could not resolve hostname macair: nodename nor servname provided, or not known

Added the hostname "macair" to /etc/hosts

/Users/apillai>tail -1 /etc/hosts
127.0.0.1       macair

After

/Users/apillai>ssh macair
Last login: Sat Feb  4 15:08:16 2012 from localhost
share|improve this answer

The man page for 'hostname' says to use scutil to set it:

% scutil --set HostName "foo.domain.com"

This worked perfectly for me.

share|improve this answer

The name is given out by your network's DNS server. If you are connected to a NAT router, then it may be providing a DNS server giving that answer by default. You will only see the “Computer Name” name in your prompt if your current network configuration does not assign a DNS name to your IP address, in which case your computer's hostname becomes “<what you entered>.local.” thanks to multicast DNS.

This is not a bug or misconfiguration — Mac OS X is doing its best to have your computer's hostname be a name by which your computer can actually be accessed on the network.

Reconfigure your router or DNS server so that it knows what name you want your computer to have.

share|improve this answer
up vote 16 down vote accepted

After a bit of playing about on the Terminal I've found a solution

sudo hostname <desired hostname>

this has permanently changed my hostname - I've tested it with a reboot and full shutdown and it seems to have done the trick! This doesn't explain why it gave me the odd hostname in the first place but that could just be because Lion is still new

share|improve this answer
    
Nice work figuring this out! Make sure to mark your own answer as accepted once enough time has passed to do so. Glad you got the problem solved; thanks for sharing. –  nhinkle Aug 3 '11 at 18:54
2  
It does not work. It sticks for a while but changes again. I think it has something to do with the lease period. –  Maciej Swic Jan 16 '12 at 8:28

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.