3

Here are two instances where I found that setting the computer name via System Preferences > Sharing > Computer Name does not really set the HostName attribute.

The macOS version is macOS High Sierra version 10.13.6 in both instances below.

Instance 1

I got a brand new MacBook Pro which had the following settings under System Preferences > Sharing.

  • Computer Name: Lone's MacBook Pro
  • Local Hostname: Lones-MacBook-Pro.local

The scutil and hostname output looked like this:

$ scutil --get ComputerName
Lone's MacBook Pro
$ scutil --get LocalHostName
Lones-MacBook-Pro
$ scutil --get HostName
HostName: not set
$ hostname
Lones-MacBook-Pro.local

Then I went to System Preferences > Sharing and set the Computer Name to luke. Now the output looked like this:

$ scutil --get ComputerName
luke
$ scutil --get LocalHostName
luke
$ scutil --get HostName
HostName: not set
$ hostname
luke.local

The HostName attribute is not set!

Instance 2

I was working on a friend's MacBook Pro who had some other HostName already set (perhaps someone else had configured it for him). He had the following settings under System Preferences > Sharing.

  • Computer Name: mmod
  • Local Hostname: mmod.local

The CLI output looked like this:

$ scutil --get ComputerName
mmod
$ scutil --get LocalHostName
mmod
$ scutil --get HostName
mmod
$ hostname
mmod

Now I went to System Preferences > Sharing and set Computer Name to luke. The output now is:

$ scutil --get ComputerName
luke
$ scutil --get LocalHostName
luke
$ scutil --get HostName
mmod
$ hostname
mmod

Again, HostName remains unaffected.

Question

I know that I can set the HostName attribute with the scutil --set HostName luke command.

My question is: Is there a macOS desktop UI element where I can view or edit this HostName attribute without having to run CLI commands?

1

There's no place in the GUI to change it, because it's typically set by an external source.

Your hostname is determined by the following (in order):

  • name supplied by DHCP/BOOTP server
  • name returned by a reverse DNS lookup
  • the localhost name (what was used to set LocalHostName value)
  • name acutal name localhost

Most routers now have the ability to "register" the DHCP lease in the DNS resolver cache. So, what's happening is this...

At some point, your Mac didn't exist as a DHCP mapping or DNS entry on your router. When it connected, it sent a request which included it's preferred hostname along with a request for an address. That preferred hostname defaulted to your LocalHostName as the first two conditions would have returned nothing. When you got the address, it "registered" that hostname with an IP.

Now, you want to change the name, but it keeps coming back to the original host - this is because the router now "knows" your machine has having that name and will overwrite it per DNS (which takes priority).

TL;DR

That name is coming from your DHCP Server and/or DNS chache. If you want to clear that out and set a new one, you'll have to do it at the router.

0

Untested but according to this articled titled: How to Change Your Computer Name on Mac OS X you can change the hostname under the System Preferences.

Under the Sharing Menu

ss1

You can click the Edit button and change the hostname

ss2

After make the above change, you'll want to make sure and restart the terminal so that the above change gets picked up.

NOTE: The above should have the same effect as doing this:

In addition to your method of using the CLI:

$ sudo scutil --set HostName [NewHostNameHere]

References

  • In my question, I have mentioned that I have tried exactly what you describe and it does not change the HostName value. I have also included scutil --set HostName luke as a possible solution in my question. Do you have an answer to the actual question I ask, i.e., Can we view or edit HostName value via macOS desktop UI? – Lone Learner Apr 15 at 8:56
  • @LoneLearner - Missed that you did these steps, there's one additional detail that seems to make the difference.. Did you restart the terminal afterwards? – slm Apr 15 at 11:20
  • @LoneLearner - others are reporting in this Q&A as well - apple.stackexchange.com/questions/30552/…. There's a detail that if you override using the scutil --set <cmds> may disable the Sharing dialog's settings from getting picked up. You may need to remove/delete them so that it'll be picked up from the GUI. – slm Apr 15 at 11:27
  • 1
    Also note that DNS host names cannot contain spaces – Steve Chambers Apr 15 at 13:36
  • @slm Yes, the results in my questions are obtained after restarting the terminal. So it seems like the HostName value can only be set via scutil --set and there is no way to view or edit it via the desktop GUI? – Lone Learner Apr 15 at 14:09

You must log in to answer this question.

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