OSX Terminal showing incorrect hostname

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]\\$ "

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


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.