Set the HostName, Computer Name, and Bonjour Name Separately in OS X
You can set unique names for how your Macs computer name appears locally, from file sharing and networking, and even Bonjour services, with the help of the scutil command. This allows you to have a custom hostname for Terminal and SSH, another friendlier name for what’s visible to others on local networks, and yet another name only visible to services like AirDrop. Here’s a brief look at each and how to set them from the command line.
To get started, launch Terminal from /Applications/Utilities/. Note the — is a double-dash, not a single – flag.
Set ComputerName in OS X with scutil
ComputerName is the so-called “user-friendly” name for the Mac, it’s what will show up on the Mac itself and what will be visible to others when connecting to it over a local network. This is also what’s visible under the Sharing preference panel.
scutil --set ComputerName "MacBook Willy"
Set HostName in OS X with scutil
HostName is the name assigned to the computer as visible from the command line, and it’s also used by local and remote networks when connecting through SSH and Remote Login.
scutil --set HostName "centauri"
Set LocalHostName in OS X with scutil
LocalHostName is the name identifier used by Bonjour and visible through file sharing services like AirDrop
scutil --set LocalHostName "MacBookPro"
Of course there’s nothing wrong with using the same name for each example as well, which is actually the default behavior of OS X.
Having individual settings will be unimportant for the majority of Mac users, but setting a custom computer name is always a good idea, though novice users are best served through the Sharing preference panel. If you do want to venture off into the command line, it may be helpful to view the brief video below which demonstrates scutil changing the hostname of a Mac OS X machine:
Finally, you can also check the current settings of LocalHostName, HostName, and ComputerName by using scutil with the –get flag like so:
scutil --get HostName
For that example, the HostName will be reported back, and if one is not set it will tell you.