Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I open Terminal I expect it to show what my PS1 is set to \h:\W \u\$.

However it's not displaying my hostname Eriks-MacBook, as displayed in System Preferences.

Instead, it's showing a random string unknownb88d120cd4b2.

How can this be fixed or reset?

This machine is brand new, and the preferences/settings haven't been changed.

share|improve this question

migrated from stackoverflow.com Nov 14 '11 at 5:20

This question came from our site for professional and enthusiast programmers.

    
Type in hostname into the prompt and press enter. What do you get? –  Blender Nov 14 '11 at 4:27
    
unknownb88d120cd4b2:~ erik$ hostname unknownb88d120cd4b2 unknownb88d120cd4b2:~ erik$ –  Erik W Nov 14 '11 at 4:43
    
But that is not what my computer's name is in System Prefs - Sharing. I changed it from default to "erik-mba" hoping that would help, but no dice. –  Erik W Nov 14 '11 at 4:45

4 Answers 4

up vote 9 down vote accepted

Gordon gives a good answer to the origin of your hostname.

If you want the name that you set in System Preferences -> Sharing -> Computer Name to show up in your prompt, replace \h with $(scutil --get ComputerName). E.g my prompt is set with

PS1="[\u@:$(scutil --get ComputerName) \W]\\$ "
share|improve this answer

Run this in Terminal to change your hostname:

sudo scutil --set HostName your_new_hostname
share|improve this answer
    
That solved my problem in Terminal and iTerm2. However, the $HOSTNAME reflected in my terminals does not match the "Computer Name" in System Preferences. Are they one and the same? Should they match? –  Erik W Nov 14 '11 at 14:26
    
I don't own a Mac (nor do I like Mac, truthfully), so I can't help you there. It doesn't seem to reflect your changes. –  Blender Nov 14 '11 at 16:54
1  
Strictly speaking: no, the need not match and, on the tech side of things, you need not worry about your computer misbehaving. However, it is certainly less confusing for YOU if there is some relationship. If your system hostname is "wopr.darpa.mil" most people would choose something like "Wopr" or "WOPR" as their "Computer Name" in System Preferences, simply to avoid confusion. –  username May 31 '12 at 19:55

OS X tries a number of things to find its "hostname". Unfortunately I don't know the exact list (and order), but I think what's happening here is that it's discovering a DNS name associated with its IP address, and using that instead of the Bonjour name it's advertising for itself (the one defined in Sharing preferences).

So why's it finding a DNS name? My guess is that your local router/DHCP server/DNS server is dynamically assigning it one, based on its ethernet hardware address (presumably b8:8d:12:0c:d4:b2). You may be able to adjust the router's settings to stop it doing this, or you could probably set the computer's DHCP client ID (in the Network Preferences, Advanced settings) to control what name it assigns you.

share|improve this answer
    
This was most helpful to me. My machine was displaying this behavior, the key point being, to it seemed to have SPONTANEOUSLY changed names, as I had never seen a different one before. So I just wasted 90 minutes checking for viruses and disk issues and such. Glad to know I can safely stop wasting time. –  conspiritech Mar 22 '13 at 18:18

Terminal is showing you the first label of your BSD hostname (assuming your shell is BASH). If your BSD hostname is yourhostname.mynetwork.com then Terminal will display only yourhostname-

So from where does the BSD hostname come? It can come from several places:

• from the file: /etc/hostconfig

• else from the file: /Library/Preferences/SystemConfiguration/preferences.plist (System ▸ System ▸ HostName)

• else the result of a reverse DNS query for your primary IP address (so you might notice a totally different hostname showing up when you visit an internet café than when connected at home)

• else your "Bonjour" hostname in System Preferences > Sharing (preferences.plist again... System ▸ Network ▸ HostNames ▸ LocalHostName)

• finally, if none of the above have been set, the BSD hostname will be simply localhost

By the way, I answered the same question a while ago over here: Mac OS X Terminal - where does the prompt name come from

share|improve this answer
    
is it possible that the reverse DNS lookup takes precedency over all other configurations on my system? –  caesarsol Nov 27 at 13:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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