macOS, by default, sets the hostname of your machine in the <name>-<machine-type> format. For example, it could be Myname-MacBook-Pro. You can change the hostname both via System Preferences and the Terminal.
Change Hostname in macOS via System Preferences
Open
System Preferences from the
Apple menu.

Open
Sharing preferences by clicking on the
Sharing icon.

Change the current hostname to your desired hostname at the
Computer Name field.

Change Hostname in macOS via terminal
Open
Terminal via
Spotlight.

Set new
hostname via
scutil using
sudo.
$ sudo scutil --set HostName newhostname
Discuss the article:
Comment anonymously. Login not required.