9

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?

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
ConfusedNoob
  • 857
  • 2
  • 12
  • 18
  • see also http://apple.stackexchange.com/questions/30552/os-x-computer-name-not-matching-what-shows-on-terminal – rogerdpack Dec 19 '14 at 17:49

1 Answers1

14

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

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
username
  • 1,368
  • 1
  • 19
  • 24
  • #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 Oct 14 '11 at 21:02
  • 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 Oct 14 '11 at 21:07
  • 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 Oct 14 '11 at 21:10
  • 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 Oct 14 '11 at 21:20
  • I think it must be 3. It isn't anywhere else and seems to change randomly... – ConfusedNoob Oct 14 '11 at 21:44
  • 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 Oct 15 '11 at 02:03
  • 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 Oct 15 '11 at 12:24
  • 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 Oct 15 '11 at 22:42
  • 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 Oct 16 '11 at 19:16