Mac OS, How to rename computer via scutil

Perform the following tasks to change the workstation hostname using the scutil command.

Open a terminal.

Type the following command to change the primary hostname of your Mac:

This is your fully qualified hostname, for example myMac.domain.com

sudo scutil --set HostName <new host name>

so for example:

sudo scutil --set HostName flame01.domain.com

Type the following command to change the Bonjour hostname of your Mac:

This is the name usable on the local network, for example myMac.local.

sudo scutil --set LocalHostName <new host name>

so for example:

sudo scutil --set LocalHostName flame01.local

Type the following command to change the computer name:

This is the user-friendly computer name you see in Finder, for example myMac.

sudo scutil --set ComputerName <new name>

so for example:

sudo scutil --set ComputerName flame01

Flush the DNS cache by typing:

dscacheutil -flushcache

Restart Mac.