MainspringGuides › Computer name
macOS Guide

Change Your Mac's Computer Name From Terminal

Updated July 2026 · 3 min read

Your Mac doesn't have a name — it has three. The friendly one you see in Finder and AirDrop, the Bonjour one ending in .local, and the Unix hostname your Terminal prompt shows. When they drift apart (or sprout a mysterious "(2)"), scutil sets all three cleanly in under a minute.

The three names, and where each shows up

See the current values before changing anything (this is also how you record the undo):

scutil --get ComputerName
scutil --get LocalHostName
scutil --get HostName

HostName is often unset by default — an error there just means macOS is deriving it automatically.

Set all three with scutil

# the display name (spaces allowed)
sudo scutil --set ComputerName "Ninas MacBook Pro"

# the Bonjour .local name (no spaces)
sudo scutil --set LocalHostName "ninas-mbp"

# the Unix hostname
sudo scutil --set HostName "ninas-mbp"

Changes take effect immediately for new connections; an open Terminal window keeps showing the old prompt until you open a new one. The undo is the same command with the previous value — which is why you ran the --get commands first. If you want to return HostName to "derive it automatically," you can leave it matching the others; that's the state most Macs should be in anyway.

Why your Mac became "MacBook (2)"

The suffix comes from Bonjour conflict resolution. When your Mac joins a network and another device is already claiming its LocalHostName — often a ghost of itself, left registered after a sleep/wake cycle or a second network interface — macOS quietly renames it with a number to avoid the clash. Repeat over months and you meet MacBook-Pro (4).

The fix is exactly the commands above: set a distinctive LocalHostName and ComputerName once, and the collisions mostly stop. If the number returns, check whether two of your own devices (or a backup restored onto a new Mac) genuinely share a name, and give one of them its own.

The System Settings route

  1. Open System Settings → General → About, click the Name field, and type the new display name — this sets ComputerName (and macOS updates the derived names to match).
  2. For the .local name specifically: System Settings → General → Sharing, scroll to Local hostname at the bottom, and click Edit….

The GUI is fine for one Mac; scutil wins the moment you're renaming several, working over SSH, or want the three names set explicitly rather than derived.

If other devices keep showing the old name after a change, they're reading stale Bonjour records. The name refreshes on its own within minutes, but you can hurry it along: toggle Wi-Fi off and on to re-announce it, and restart the responder on the Mac itself with sudo killall -HUP mDNSResponder — a restart of one process, not a reboot. Your Terminal prompt, meanwhile, shows the new HostName only in windows opened after the change; old windows keep the name they started with. The three scutil --get checks from the start of this guide are also the quickest way to confirm everything landed as intended.

Identity fixed. Behavior next.

Mainspring turns 90+ hidden macOS settings into labelled, reversible toggles — so the Mac with the tidy name gets equally tidy behavior.

Try Mainspring free →

Signed & notarized by Apple · 1-day free trial · $29 once

Names sorted — now find the address

The natural follow-up when you're tidying network identity is knowing where your Mac lives on the network — our guide to finding your IP address from Terminal takes thirty seconds.