3

Starting with Big Sur, I have trouble setting the hostname for my machine. If I go to Settings > Sharing and set the computer name to <myhostname>, it will set my hostname to something like DESKTOP-66SJRDC. I have no idea where that value comes from.

Then I set the hostname manually in Terminal via

sudo hostname <myhostname>

and it seems to use the correct hostname now. However once I change the Computer Name again in Sharing it falls back to some random value and I have to set it in terminal again.

I remember just needing to set the Computer Name in earlier macOS versions and not messing about with hostname. Did something change in Big Sur?

Where does the random value come from?

  • For me my old name was still present in Sharing, but a similar one to yours was set in Terminal. Now, I changed it via Terminal and it seems to work. I will observe.

    It started with the update to Big Sur

    – peshkira Sep 29 '21 at 07:31
  • My hostname is apparently being set via DHCP. Instead of my computer name (set in Sharing) showing in my prompt, for example, or when running the hostname command, the name assigned to my computer by the network admin shows. I guess the network/DHCP-assigned name, when one exists, must take precedence over the locally-set hostname. – leanne Dec 02 '23 at 05:10
  • @leanne how can I check this for myself? Is there a way for me to know if DHCP is overriding my usual name? via the terminal – Sidharth Ghoshal Feb 27 '24 at 21:02
  • @SidharthGhoshal: I knew what my network hostname was by looking at my router's DHCP settings. This network hostname was showing in my Terminal prompt. For example, the prompt showed something like myname@networkname $ instead of myname@computername $, with computername being what I set in Sharing. – leanne Feb 28 '24 at 22:25
  • @SidharthGhoshal: I fixed it with this tip from Reddit --> computer_name=${"$(scutil --get ComputerName)"//\%/%%} followed by PS1='%n@$computer_name...' placed in my .zshrc file. – leanne Feb 28 '24 at 22:36

0 Answers0