Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DominikHoffmann

macrumors 6502a
Original poster
Jan 15, 2007
537
531
Indiana
My /etc/zshrc has the unsurprising lines:

Code:
# Default prompt
PS1="%n@%m %1~ %# "

This becomes

Code:
userID@computername ~ %

When I open a terminal window. The problem is that computername is not my computer name, but the name of a different Mac on my network. I also don’t have a ~/.zshrc file that would set it explicitly.

So the question is: What sets the variable %m? Once I know that, I can maybe correct whatever the corresponding configuration file is.
 
I don't know what causes it, but I've seen it happen in the bash days (when I was at a conference, on their Wi-Fi). I suspect that looking around in zsh itself is probably setting you up for a wild goose chase.
 
  • Like
Reactions: DominikHoffmann
What does hostname say?

Maybe the mDNS is borked. Or something like that.
It just went from “cold” to “warm.”

Bash:
userID@othercomputername ~ % hostname
othercomputername.localdomain

Okay! So what sets the hostname? If not Settings → General → Sharing → Local Hostname:
Screenshot 2023-04-03 at 10.49.12 PM.png

… and the blurred-out name is the correct computer name, not the othercomputername from above.
 
… and it’s getting “hot!”

Here is what is happening. My system gets its hostname from my internet gateway, which provides DHCP on its LAN interface. The DHCP server is configured with static leases which are keyed to the computers’ LAN interfaces’ MAC addresses. The thing is I recently started using a Belkin USB-C to Ethernet adapter that my son had been using for a while. Therefore the DHCP server recognized it as my son’s computer and assigned to it the IP address he had been using, when he was using that Belkin adapter. The DHCP server also assigns a hostname, along with an IP address, for its internal DNS server. When the networking framework of my computer queried the internet gateway’s DNS server about its hostname, it received my son’s computer’s host name.

Pretty convoluted, I know!

The fix was to adjust the static leases in the LAN interface’s DHCP server.
 
  • Like
Reactions: Brian33
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.