Set a Mac's Hostname

To set the permanent hostname, use the scutil utility (enter the desired hostname instead of the_hostname):

sudo scutil --set HostName the_hostname

Credits