Changing the hostname
Changing the hostname
hostname --changeRename a machine so the name sticks — in the shell, on the network, and after a reboot.
Every box in a homelab ends up named something. The trap is that “the hostname” is not one value on either OS, so renaming half of it leaves you with a machine that answers to two names.
Rename it
macOS keeps three separate names, and scutil sets all three.
| Name | What uses it |
|---|---|
ComputerName | Finder, AirDrop, the Sharing pane. Spaces and emoji allowed |
LocalHostName | Bonjour, the .local address. Letters, digits and hyphens only |
HostName | What hostname and the shell prompt return |
Set all three
sudo scutil --set ComputerName "Rack 01"
sudo scutil --set LocalHostName "rack01"
sudo scutil --set HostName "rack01"Read any of them back with scutil --get ComputerName.
Set
HostName explicitly even if the other two look right. When it is unset,
macOS takes the name from DHCP and will rename itself back the next time it
picks up a lease.Flush the caches
sudo dscacheutil -flushcacheBonjour keeps advertising the old .local name until it does.
Open a new terminal
The prompt is built at login, so the window you typed this in keeps the old name until you replace it.
Verify
hostname
scutil --get HostNameNew shell, and both should agree.