Skip to content
Changing the hostname

Changing the hostname

hostname --change

Rename 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.

NameWhat uses it
ComputerNameFinder, AirDrop, the Sharing pane. Spaces and emoji allowed
LocalHostNameBonjour, the .local address. Letters, digits and hyphens only
HostNameWhat 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 -flushcache

Bonjour 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 HostName

New shell, and both should agree.

This post is licensed under CC BY 4.0 by the author.
Last updated on