Here’s how to change your Mac hostname with the command line and make it permanent:
Important thing it is very case sensitive use HostName same as below
sudo scutil –-set HostName new_hostname
Simply replace new_hostname with whatever you want your hostname to be changed to, for example I want to change my Mac’s hostname to MacBookPro, I will use this command:
sudo scutil –-set HostName MacBookPro
(Note the “–” before set is two dashes next to each other, –set)
You will be asked for your admin password since you’re using the sudo command.
After the command is executed you can verify that the changes took place by typing:
Changing the computer name and Local Hostname by going System Preferences “ Sharing” change the computer name and local host name.
You can also set a temporary hostname change by using the following command:
sudo hostname new_hostname
This will reset itself after your Mac reboots though, so if you want a permanent hostname change, use the above command instead