Apple - OS X computer name not matching what shows on terminal

It's perfectly normal for this to occur; when you login Terminal remotely bash does a reverse DNS lookup. It will only be the same if the hostname is not specified on the network you're connecting from and there is no reply from the DHCP server, or the reverse lookup against the remote DNS server fails to resolve.

You can easily over-ride the default setting by using this command in Terminal:

# sudo scutil --set HostName archos

You can check it by using:

# nslookup nn.nn.nn.nn
( or )
# host nn.nn.nn.nn

(where nn signifies your Mac's ip address)

You may also want to change some other things using the scutil command:

sudo scutil --set ComputerName "newname"
sudo scutil --set LocalHostName "newname"
sudo scutil --set HostName "newname"

There are two potential reasons for the shell ($HOSTNAME variable, '\h' in $PS1) and the hostname utility to report a hostname that differs from the one shown in System Preferences > Sharing:

  • sudo scutil --set HostName newName was used to persistently change the hostname - unfortunately, this value is independent of the LocalHostName value set by System Preferences behind the scenes - even though man hostname suggests this method, DO NOT USE IT for that reason; run sudo scutil --set HostName '' to remove it, at which point LocalHostName should again be reported; for background, see this post by @Lauri Ranta.

  • [Update: The following is no longer true as of OSX 10.10] If your /etc/hosts file has an entry that matches your machine's IP address, that entry's name will be reported.

Only if neither of the above is true will the shell and hostname reflect the value set via System Preferences.

If you want to change your hostname from the shell, run both of the following:

  • sudo scutil --set LocalHostName <newName>
  • sudo scutil --set ComputerName <newFriendlyName>

where <newFriendlyName> can be a friendlier version (spaces, punctuation) of <newName> (alphanumerics and dashes only).