Change your Mac Hostname via Terminal

Sep 6, 2010 - 17 Comments

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.

Related articles:

Posted by: Manish Patel in Command Line, Mac OS X, Tips & Tricks

17 Comments

» Comments RSS Feed

  1. Arnan says:

    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.

  2. Jim says:

    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.

  3. George says:

    It’s “–set”, not “-set”.

  4. Josh The Geek says:

    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!

  5. [...] command to do that is: scutil –set HostName YOURHOSTNAME (found info here: http://osxdaily.com/2010/09/06/change-your-mac-hostname-via-terminal/ – [...]

  6. [...] gefunden osxdaily.com. Danke Jim [...]

  7. Paul says:

    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!

  8. rvn says:

    how can i remove localhost on my command line?

  9. Chrisb says:

    Useful!!! Thanks.

  10. 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?

  11. Philip says:

    Thanks, it was very useful

  12. Steve says:

    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?

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Shared on Facebook

Shop at Amazon

Ad

OSXDaily on Facebook