Change macOS computer name using Terminal


Run these three commands to change the computer name that your terminal displays

sudo scutil --set ComputerName "mycoolmacbook"
sudo scutil --set LocalHostName "mycoolmacbook"
sudo scutil --set HostName "mycoolmacbook"

Flush the DNS cache by typing:

dscacheutil -flushcache

Restart your Mac.

It didn’t work for me, had to restart my mac for new name to show.