Hostname issue in Mac OS X Lion

21,553

Solution 1

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

Solution 2

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

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

This worked perfectly for me.

Solution 3

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.

Solution 4

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

Solution 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:
21,553

Related videos on Youtube

Mikey
Author by

Mikey

Updated on September 18, 2022

Comments

  • Mikey
    Mikey almost 2 years

    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!

    • Gordon Davisson
      Gordon Davisson almost 13 years
      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.
  • nhinkle
    nhinkle almost 13 years
    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.
  • Maciej Swic
    Maciej Swic over 12 years
    It does not work. It sticks for a while but changes again. I think it has something to do with the lease period.