How to set hostname in Mac OS X with scutil

The manpage is kind of self explaining, send me a message if you need some more help.

 

The commands I used:

man scutil

Manage system configuration parameters.

Examples

Display the current hostname, localhost name and computername

Change the primary hostname of the computer to cedric.local (local) or cedric.ss64.com (fully qualified)

Change the Bonjour hostname of the computer on the local network, to cedric.

Change the computer name to Cedric, this is the computer name you see in Finder.

 

Source: https://ss64.com/osx/scutil.html