Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

This question already has an answer here:

When I setup my computer I named it "Scott's MacBook Pro". And so when I go to System preferences->Sharing, it says Scott's MacBook Pro there as my computer name. However, opening up a terminal gives me this prompt:

Last login: Sun Oct  7 11:02:49 on ttys003
new-host-4:~ scott$ 

When I login to Backblaze, they list my computer as "new‑host‑4_2012_10_07". Did I not fully set my computer name? Should I use the traditional hostname command?

share|improve this question

marked as duplicate by grgarside, patrix Nov 15 '13 at 21:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

To my knowledge this is what DNS reports it to be. If your IP-number does not have a name, the name from Preferences is used (perhaps the .local domain)) –  Thorbjørn Ravn Andersen Oct 7 '12 at 18:30
@ThorbjørnRavnAndersen - my .local domain from the Sharing preferences has been scotts-macbook-pro.local –  at01 Oct 7 '12 at 20:15

8 Answers 8

After following Jeffrey J. Hoover's tip,

sudo scutil --set ComputerName "newname"
sudo scutil --set LocalHostName "newname"
sudo scutil --set HostName "newname"

I would add these last two steps.

  • Flush the DNS cache by typing: dscacheutil -flushcache
  • Restart your Mac.

EDIT: It didn't work for me until I restarted my mac.

share|improve this answer
Are you a former Windows user, carrying over the practice of rebooting after every little change, or do you actually have evidence that it's necessary to restart? –  iconoclast Aug 12 at 19:37
@iconoclast Last used Windows primarily in 2004. Restarting worked for me and 16 other people. Wouldn't hurt. –  Danger14 Aug 13 at 19:31
Meaning it didn't work until you restarted? (Restarting can hurt when you actually do serious work on your computer, and therefore have lots of applications open. Getting everything back how you had it before reboot can be a *****.) Also, the fact that 16 people found some part of your answer helpful doesn't mean nothing worked until they restarted. –  iconoclast Aug 13 at 19:32
Worked for me without restarting, just quit Terminal completely and re-open. –  Alexander Wigmore Aug 20 at 13:06
I first used scutil --get to discover that ComputerName and LocalHostName had been correctly set by using System Preferences (Sharing). However, it told me that HostName was not set. Thus, I just used sudo scutil --set in order to set HostName. Then, I didn't need to use dscacheutil or do a reboot as immediately a check of hostname showed that things were fixed for me and opening a new Terminal tab showed my prompt was now fixed too. (OS X 10.9.4) –  Quintin Willison Aug 28 at 8:13

If you use:

sudo scutil --set HostName name-you-want

it will work a bit better. From the scutil(8) man page:

--get pref
    Retrieves the specified preference.  The current value will be
    reported on standard output.

    Supported preferences include:
          ComputerName   The user-friendly name for the system.
          LocalHostName  The local (Bonjour) host name.
          HostName       The name associated with hostname(1) and gethostname(3).

--set pref [newval]
    Updates the specified preference with the new value.  If the new value is not
    specified on the command line then it will be read from standard input.

    Supported preferences include: ComputerName LocalHostName HostName

    The --set option requires super-user access.
share|improve this answer
Worked for me after running that command and rebooting Terminal. –  Johnathan Elmore Jul 28 at 16:04

For those who are not looking for a command line solution, you can change it under

System Preferences -> Sharing -> Computer Name: 
share|improve this answer
This didn't work for me. The name at terminal command prompt still remained as localhost –  erthad Sep 5 at 15:34

You can run

sudo hostname Name-Of-My-Computer

in Terminal to change the name.

share|improve this answer
The man page for hostname says to run scutil --set HostName name-of-host if you want to keep the hostname across reboots –  daviewales Feb 8 '13 at 5:30

I am adding an answer here because I have recently run into this problem as well.

In OSX 10.7.4 and possibly prior, there appears to be a bug in the Edit Hostname option in the Sharing preference panel. It sets the hostname to the last thing set instead of the current this set.

I had to run sudo hostname [preferred hostname] in order to set it correctly, after setting it in Sharing.

share|improve this answer

In my case, I found that it was a problem with our DNS server, as the reverse DNS lookup didn't scavenge because there was duplicate DNS entries for the IP address and hostname.

share|improve this answer
up vote 0 down vote accepted

I didn't do anything to my computer, but eventually for some reason the hostname and computer name all registered as the name I initially set! In fact I had the following terminal open the whole time and this is exactly a cut and paste:

new-host-4:~ scott$ hostname
new-host-4:~ scott$ hostname
share|improve this answer

You can define what you want to see before the $ in your terminal by modifying the file ~/.profile.

For example if you add to the file ~/.profile the following line:

# h is the host name, w the complete path 
export PS1="\h:\w$ "

you will see the host name and the complete path of the current directory:


You can also modify my example by using the following options in the export command:

\d – Current date
\t – Current time
\h – Host name
\# – Command number
\u – User name
\W – Current working directory (i.e: Desktop/)
\w – Current working directory, full path (i.e: /Users/Admin/Desktop)
share|improve this answer
Why -1? He said that he cannot see its host name in the Terminal. –  Maverik Oct 7 '12 at 18:38
wasn't me with the -1 :). Thank you for your answer, I guess I'm not just looking for how to change my name in the terminal, but clearly my computer is still referenced by the new-host-4 ugly name as services like Backblaze use it. My previous MacBook Pro had a nicer name that I chose, I don't know why my mountain lion MacBook Pro isn't using the name I have in the Sharing preferences –  at01 Oct 7 '12 at 20:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.