16

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!

1
  • 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. Aug 3, 2011 at 15:23

5 Answers 5

15

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

2
  • 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, 2011 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. Jan 16, 2012 at 8:28
11

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

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

This worked perfectly for me.

4

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.

2

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
2

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.

You must log in to answer this question.

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