Change your Mac Hostname via Terminal
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.
Here’s how to change your Mac hostname with the command line and make it permanent:
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:
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:
hostname
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. 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.

Keep in mind that this does NOT work for users who have an empty (no) password. Since sudo (or terminal in general) demands a password of at least 1 character.
With the command you give, the change will last only until the next reboot; it’s not permanent, and it doesn’t change the config files that need changing, under /Library/Preferences/SystemConfiguration.
According to the man page for ‘hostname’, to make the change permanent — this is only for OS X client not server — you must run this command:
scutil –set HostName name-of-host
…where you replace ‘name-of-host’ with your new hostname.
On OS X Server you would use the ‘changeip’ utility to update all the plists under /Library/Preferences and /Library/Preferences/SystemConfiguration. Despite its name, changeip can be used to change the server’s IP address, hostname, or both.
Thank you for pointing this out Jim, I adjusted the article accordingly.
-Manish
Hi Manish,
Just to not, it’s suppose to be “–set” with the double dash there. Not sure if the — will be converted, but here’s the one with spaces in between “- – set”.
It’s “–set”, not “-set”.
This is really annoying. Every now and then, I open Terminal and see my hostname is wrong. I use apache and have many local test sites, and it is always changed to one of the site addresses. In console, I see ‘setting hostname to ‘macbook-pro.local”, and less than five seconds later, ‘setting hostname to ‘test1.drupal.localhost”, always by configd. What’s interesting is when firefox logs something about the same address, which I’ve not accessed in a month. ??? I use scutil –set HostName macbook-pro.local to reset it. This helps, now I wont need to. Thanks!
[...] command to do that is: scutil –set HostName YOURHOSTNAME (found info here: http://osxdaily.com/2010/09/06/change-your-mac-hostname-via-terminal/ – [...]
[...] gefunden osxdaily.com. Danke Jim [...]
I notice that my iMac sets its hostname to “eyeconnect (pauls-imac).home”. I want to know why an application which I deleted all traces of (or at least thought I did) is inserting its presence in my hostname? Can anyone explain it? It’s driving me nuts!
how can i remove localhost on my command line?
Useful!!! Thanks.
It doesn’t work
I wrote:
“scutil -set HostName helplessnerd”
And the only response I’ve got:
“scutil: unknown, type “help” for command info”
Can somebody help me?
Make sure you use a double dash like — for set flag:
scutil –set HostName “helpnessnerd”
Thank you! but I still get the same response.
Really confusing…
I think when you re-start the terminal, you will see your changes.
Thanks, it was very useful
It does not work. What is wrong with Apple? It still says the wrong host name and I can’t seem to figure out how to change it. Any suggestions?