Where does the prompt name come from in the macOS Terminal?

5

Where does the word at the beggining of the prompt on my MacBook Pro terminal come from?

At the moment, it looks like this

Last login: Fri Oct 14 12:55:34 on ttys000
sherrythinkpad:~ ConfusedNoob$ 
sherrythinkpad:~ ConfusedNoob$ 

Obviously, the ConfusedNoob is my username - but where on Earth is sherrythinkpad coming from?

ConfusedNoob

Posted 2011-10-14T19:59:58.287

Reputation: 647

Answers

11

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

username

Posted 2011-10-14T19:59:58.287

Reputation: 1 178

#2 is where the default value of #4 is stored, not a separate thing. #3 is used before #2/#4, which is what ConfusedNoob is seeing. – Kevin Reid – 2011-10-14T21:02:38.827

true, Kevin — yes, if you want to get specific. but since there is no place in the GUI, unless you have Server app installed, to set the former, I had to list the file. – username – 2011-10-14T21:07:07.837

hang on a sec ;) #3 is most certainly not used before #2 — that would defeat the whole purpose. this is because #2 is a replacement for hostconfig, and is meant to allow one to override any other values, like a changing reverse DNS name. there would be no point setting a static hostname if it were to simply be steamrolled as soon as you connect to a network... aw crap, this is more complicated than the original poster probably wanted :( – username – 2011-10-14T21:10:01.263

at any rate the original poster would likely not have a value defined for System ▸ System ▸ HostName unless he has installed the Server OS — the name he's seeing is likely the Bonjour name, unless he's got a public IP or a private DNS server running on his local network – username – 2011-10-14T21:20:52.203

I think it must be 3. It isn't anywhere else and seems to change randomly... – ConfusedNoob – 2011-10-14T21:44:11.257

Sorry, I was not aware of this Server aspect. I looked at my copy of the file and found my hostname in it, and I assumed that it was set from the Sharing preferences. I like how you added the key paths in the file to clarify. – Kevin Reid – 2011-10-15T02:03:32.930

Note that Apple officially refers to the Bonjour name as the "Local Hostname." I mention this to clear up any confusion if you change it in System Preferences > Sharing. At any rate, it's the one that ends in ".local" – username – 2011-10-15T12:24:25.870

If it changes all the time it is definitely coming from a reverse DNS lookup. It's quite harmless — count yourself lucky that your network admins aren't giving you a generated name like DHCP124A3E243 ;) – username – 2011-10-15T22:42:09.510

one last comment, depending on how your network admin designed your local network, you might be able to influence the DNS records by setting a "DHCP Client ID" in your Network Preferences. Some networks set reverse DNS for an IP to this — most do not – username – 2011-10-16T19:16:34.900