17

There are tons of questions about changing a Mac hostname, and while I went through most of them, I could never find this nuanced answer:

Why do routers always seems to receive the first hostname that was ever set to a machine? Let me show you with these screenshots how this Mac is supposedly correctly setup according to various answers on this site:

System Preferences showing Sharing settings Terminal showing hostname informations

Now, when i set up this computer years ago, I think I chose the hostname david-MBP, and this seems to be what various routers get to this day and sometimes return to the Mac for localhost operations. Later I changed it with the various Terminal commands, and the Mac knows it, but it seems to stick around when communicating with routers.

Router configuration with erroneous settings

So now my question is where do OS X keep this old value? Because since I connected with this router in the screenshot above, I never had that hostname, so it's no DHCP cache or anything like that.

9
  • Did the host david-macbook-pro ever have the name david-MBP?
    – klanomath
    Oct 20, 2015 at 8:11
  • Yes, I wrote it a bit contorted: when i set up the Mac, I did use that host name. Over the course of time, I changed it numerous times with any common command, and on the machine it changed. But the one that get read by routers really seems to stick.
    – mcdado
    Oct 20, 2015 at 8:14
  • 1
    So it's not a OS X problem but one of the router OS (probably some Linux descendant). Once the hostname is set the router doesn't update it properly in its hosts database!
    – klanomath
    Oct 20, 2015 at 8:21
  • My last point in the question though is that this router met my Mac like a month or so ago, but my Mac has been in this setup for months/years. So there is some setting somewhere in OS X lurking around.
    – mcdado
    Oct 20, 2015 at 8:24
  • Check your nvram with nvram -p | grep david
    – klanomath
    Oct 20, 2015 at 8:34

5 Answers 5

12

There are three different hostnames that macOS/OS X uses:

  • ComputerName
  • HostName
  • LocalHostName

Each of these values can be found in /Library/Preferences/SystemConfiguration/preferences.plist


ComputerName

scutil --get ComputerName

This is Apple "friendly" name for the computer and can be found in System Preferences >> Sharing >> Computer Name. According to the man page for scutil, it is described as "The user-friendly name for the system."

According to Apple, the ComputerName is The AppleTalk name and the default name used for SLP/DA1. It's a zero-configuraiton protocol that allows you to set up a simple network without a DNS/DHCP server but allow you to reach the different resources via a host name.

HostName

scutil --get HostName

According to the scutil man page, the HostName is "the name associated with hostname(1) and gethostname(3)". This name can come from any of the following sources:

  • The name provided by the DHCP or BootP server for the primary IP address
  • The first name returned by a reverse DNS (address-to-name) query for the primary IP address
  • The local hostname
  • The name “localhost”

(In my virgin install of El Capitan, the HostName defaulted to LocalHostName)

LocalHostName

scutil --get LocalHostName

This is for Bonjour2 services on the LAN. This is how, on a small LAN without DNS/DHCP, Apple computers can discover and interact with resources such as file sharing on other machines, printers, etc. This name gets set when you initially configure your Mac.

TL;DR

It is using "the first name you ever set" because during initial setup, it set the LocalHostName which it assumed would forever be. When you re-configured using the GUI, you changed the ComputerName which did not modify the LocalHostName.

If you wish to fix this in your router, simply set your LocalHostName using the command:

scutil --set LocalHostName MyNewComputerName.domain


1 SLP/DA Service Location Protocol/Directory Agent. The Service Location Protocol is a service discovery protocol that allows computers and other devices to find services in a local area network without prior configuration.

2 Bonjour is Apple's implementation of zero-configuration networking, a group of technologies that includes service discovery, address assignment, and hostname resolution.

1
  • 2
    I think there is a 4th... The NetBIOS name which you can get from defaults read /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName
    – NightWolf
    Apr 20, 2021 at 7:16
7

The routers will usually acquire the name of the computer when the IP address has been assigned, which is before any sharing or broadcasts are done. The computer name is/can be defined in Network Preferences under DHCP Client ID and is independent from any other computer setting. Essentially it means "when asking for an IP address, identify yourself as /this/". Check if you have it set like this:

dhcp client id

1
  • 1
    this solved a problem with inconsistent hostnames in sharing preferences. Jul 24, 2020 at 20:59
0

For those who still got this issue after several years: Ask your IT to clear the DNS reverse lookup zones for your IP. Or if they have the WINS server, clear the Netbios name linked to your IP.

0

I was able to find out the issue. Your router is keeping the device name stored. To fix it do this:

  1. Log into your router admin interface
  2. Click "Attached Devices" (or the corresponding screen in your router that tracks the devices currently connected to it.)
  3. There you will see the device name you want to update
  4. Now go to the "access control list" screen on your router (this screen allows you to black/white list which devices are allowed to connect)
  5. Activate the access control feature and then edit the entry that shows the device name you want to update
  6. Simply delete the device name and click update enter image description here
  7. Go back to the "attached devices" screen (or the corresponding on your router) and you will now see that it has updated to display your current macbook device name (As your original post explained, you change the device name: "system preferences" -> "sharing".)
  8. This fixed the issue for me. Hope that helps.
0

I followed the instructions that Allan posted but like Giant Smptu, had to update my router. I have a Deco Mesh wifi network. I needed to delete my computer out of the router settings and let it connect again, but it wouldn't let me do this on my Deco Mesh setup unless I was offline. So the steps for me were to:

  1. Turn off wifi on my Macbook.
  2. Log into the Deco app on my phone.
  3. Swipe down to refresh the list of devices and...wait.
  4. See that my computer name vanished.
  5. Go into offline devices

Click device name under "offline"

  1. Tap on my old computer name, click the gear icon.

Click the Gear

and then ellipses and choose delete.

Click Delete

  1. Turn your computer's wifi back on and it should connect w/ the new name in the router.

You must log in to answer this question.

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