OS X – Set the HostName, Computer Name, and Bonjour Name via command line
Instead of wading through the various GUI options you can set the unique names for how your computer name appears locally with the help of the scutil command. The following command will set all names to “MacMuffin”:
sudo scutil --set ComputerName "$MY_NAME" && \
sudo scutil --set HostName "$MY_NAME" && \
sudo scutil --set LocalHostName "$MY_NAME" && \
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "$MY_NAME"
ComputerName: is the user-friendly name of your Mac. It 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 is visibule under the Sharing preference panel:
Hostname: is the name assigned to the computer as visible from the command line and it is also used by local and remote networks when connecting through SSH and Remote Login.
LocalHostName: is the name identifier used by Bonjour and visible through file-sharing services like Airdrop.