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 George Garside, 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
add comment

8 Answers 8

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
add comment

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.
share|improve this answer
add comment

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:

host_name:current_directory_path$

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
2  
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
    
ezprompt.com is awesome for generating custom PS1s –  XAleXOwnZX Jan 25 at 22:27
add comment

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
add comment

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
add comment

You can run

sudo hostname Name-Of-My-Computer

in Terminal to change the name.

share|improve this answer
5  
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
add comment
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.home
new-host-4:~ scott$ hostname
Scotts-MacBook-Pro.local
share|improve this answer
add comment

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
add comment

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