81

For three days straight, I have connected to the public WiFi network at my local library. Each day, I have seen a different prompt in Terminal. Here are some of the prompts I've seen:

zp-pc:~ russell$
mary-pc:~ russell$
normob05:~ russell$

I have check under System Preferences -> Sharing, and my computer name is "Russell's Mac". Also, I set the DHCP Client ID to "RUSSMAC" under System Preferences -> Network -> Advanced -> TCP/IP, but I still see the random host names at the Terminal prompt.

Why is my computer name changing every day?

122

Type in Terminal:

scutil --get HostName

If there's no HostName available, what you see is probably coming from the DNS or DHCP server.

Set your HostName with:

sudo scutil --set HostName 'yourHostName'

That should do it.

| improve this answer | |
  • 1
    Thanks! This fixes an annoyance with my company's VPN, and unlike Pulse Secure's KB article your solution works on OS X 10.11. – Robert Calhoun Apr 6 '16 at 13:42
  • 1
    Works on 10.12 too! I still wonder, why the value returned by \h in my PS1 string changed though. – ohaleck Oct 28 '16 at 12:32
  • 10.13.1 and still working cheers – Mazz Nov 12 '17 at 12:19
  • Solved on 10.15.X too, thank you man – MatPag Apr 27 at 10:12
24

Found the answer here, though there is some discussion about the details.

In short, the Mac will pick up a host name from the DHCP server. This does not affect your computer's name as you have assigned it. This will only affect what you see at the command prompt.

| improve this answer | |
  • 1
    It's a short discussion of this exact issue. The conclusion is that you're seeing a name that was given to you by the computer that assigned you an ip address. In other words, the library's wifi gave me a random name that it picked up from some other computer that previously connected to their wifi. – Russell Thackston Dec 14 '14 at 1:58
  • what was the "answer" mentioned then? Just that it's benign to go ahead and ignore? – rogerdpack Dec 14 '14 at 7:02
  • Correct. BTW, the link is working now. It looks like klanomath fixed it. – Russell Thackston Dec 17 '14 at 12:31
4

Very simple easy solution ...

  1. sudo hostname [name-of-host]

  2. Enter hostname and see your new hostname set

e.g.

doolally:~ sjohnson$ sudo hostname AllTheRage
doolally:~ sjohnson$ hostname
AllTheRage

Login back in or restart terminal to refresh ...

Also, check usage of hostname in man hostname.

| improve this answer | |
1

I noticed my hostname listed in the terminal prompt had changed. I found the same name configured in my network settings in the WINS tab. Seemed to be associated with a workgroup from my office (perhaps from connecting to my corporate VPN). Anyhow, I left it alone and simply used the sudo scutil command listed above to set my hostname and it resolved the issue. Closed terminal and opened a new one; all is good.

| improve this answer | |
-1

This is very late, but hopefully this helps those in the future who run into this problem. After a lot of research the somewhat long but most simple answer I found was to:

  1. Open System Preferences > Network
  2. Click the location dropdown menu
  3. Select "Edit Locations..."
  4. Click the plus button to add a new location
  5. Add a new location by giving it a name
  6. Click Done
  7. Click Apply (instructing it to use the new location)
  8. Open new Terminal window

That should do it.

| improve this answer | |
  • 9
    should do what? – cvogt Jun 4 '15 at 22:21

Not the answer you're looking for? Browse other questions tagged .