Change your Mac Hostname via Terminal
Need to change the hostname of a Mac? For most people if you want to change your Mac computer name you just do it through the Sharing system preference, it’s quick and very easy. For those of us that are more geekishly inclined, we like to do things through the Terminal.
This tutorial will show how to change your Mac hostname with the command line and make the setting change permanent (well, permanent until you change it again):
How to Change Host Name on Mac from the Command Line
To get started, launch the Terminal application in Mac OS and then use the following command syntax:
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 a 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.
Another Method for Setting the Mac Hostname
With modern MacOS releases from Mac OS X Mavericks and newer, you can also use the hostname command with a flag to set the hostname to be permanently changed:
sudo hostname -s YourHostName
Again, sudo requires admin privileges to complete the job.
Checking the Current Mac Hostname from the Command Line
After the above command is executed you can verify that the changes took place by typing:
If you want to watch this done, the short video below walks through the steps by using scutil:
Setting a Temporary Hostname Change
You can also set a temporary hostname change by using the following command:
sudo hostname new_hostname
This particular approach is temporary and will reset itself after your Mac reboots though, so if you want a permanent hostname change, use the above command instead. You can still use the hostname command but it will require the -s flag as discussed in the aforementioned instructions. Thank you to commenter Jim for pointing this out!
That’s all there is to it. By default Mac OS X will usually assign the hostname as whatever the admin account username is. Changing your Mac’s hostname can make it easier to find your Mac on a network and to connect to.