How to Set the HostName, Computer Name, and Bonjour Name Separately in Mac 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.
How to Set Individual Computer Names, Host Names, and Bonjour Names on Mac
To get started, launch Terminal from /Applications/Utilities/ as this walkthrough requires the use of the command line. It’s also important to note the — is a double-dash, not a single – flag.
Set Individual Computer Name in Mac OS X with scutil
ComputerName is the so-called “user-friendly” computer name for a 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"
How to Set Unique HostName in Mac 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"
How to Set Unique LocalHostName in Mac 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 Mac 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:
How to Get Current Host Name, Computer Name from Mac Command Line
Finally, you can also check the current settings of LocalHostName, HostName, and ComputerName by using scutil with the –get flag like so:
Getting the host name:
scutil --get HostName
Getting the computer name:
scutil --get ComputerName
Getting the Bonjour local host name:
scutil --get LocalHostName
For these examples, the HostName, Bonjour Name, or Computer Name will be reported back, and if one is not set it will tell you.