108

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?

1

5 Answers 5

170

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.

9
  • 2
    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. Commented Apr 6, 2016 at 13:42
  • 2
    Works on 10.12 too! I still wonder, why the value returned by \h in my PS1 string changed though.
    – ohaleck
    Commented Oct 28, 2016 at 12:32
  • 1
    10.13.1 and still working cheers
    – Mazz
    Commented Nov 12, 2017 at 12:19
  • 1
    Solved on 10.15.X too, thank you man
    – MatPag
    Commented Apr 27, 2020 at 10:12
  • 1
    Still valid in Dec 2021 Commented Nov 15, 2021 at 12:55
41

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.

4
  • 2
    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. Commented Dec 14, 2014 at 1:58
  • 1
    what was the "answer" mentioned then? Just that it's benign to go ahead and ignore?
    – rogerdpack
    Commented Dec 14, 2014 at 7:02
  • Correct. BTW, the link is working now. It looks like klanomath fixed it. Commented Dec 17, 2014 at 12:31
  • Same story. Renaming computer in "Sharing" preferences not changed host name everywhere. Host name in Terminal and Hints in "Sharing" preferences were not up to date. Also in "Networking" preferences "WINS -> NetBIOS Name" was wrong. Restarting WiFi Access Point resolved an issue.
    – Vlad
    Commented Mar 10, 2023 at 20:52
7

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.

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.

-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.

1
  • 11
    should do what?
    – cvogt
    Commented Jun 4, 2015 at 22:21

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