trio.so
How-Tos

How to Change the Hostname on a Mac (MacBook, iMac, Mac mini)

Change a Mac hostname in System Settings or Terminal with scutil: ComputerName, LocalHostName and HostName explained, plus renaming a fleet by script.

Mountain landscape representing leadership perspective and vision
Written by
Atena Ladchartabi

Content writer, trio.so

Published on
Modified on

To change the hostname on a Mac, open System Settings > General > About and edit the Name field. That sets the computer name. To set all three names from Terminal, run sudo scutil --set ComputerName "NewName", sudo scutil --set LocalHostName "NewName" and sudo scutil --set HostName "NewName". Use no spaces in the last two. Check the result with scutil --get HostName.

ComputerName, LocalHostName and HostName: what each one does

A Mac keeps three names, and "hostname" can mean any of them. That is why the name in Finder can differ from the name in Terminal.

NameWhere you see itRules
ComputerNameSystem Settings > General > About, Finder sidebar, AirDrop, SharingFree text. Spaces and capitals are fine.
LocalHostNameBonjour, as name.local on the local networkLetters, numbers and hyphens only. Not case sensitive.
HostNameThe shell prompt, hostname command, DNS and command line toolsA fully qualified or plain name. If it is not set, macOS falls back to another source.

Apple documents the first two in its guides. When you change the computer name in System Settings, macOS also updates the local hostname, replacing spaces with hyphens, so "My Computer" becomes My-Computer.local. If another Mac on the network already uses the name, macOS adds a number to it.

Change the computer name in System Settings

  1. Choose Apple menu > System Settings, then click General in the sidebar.
  2. Click About.
  3. Select the name in the Name field and type the new one.

To set the local hostname on its own, go to General > Sharing, click Edit in the Local hostname section at the bottom, enter the new name and click OK. These are the steps on macOS Ventura 13 and later. On older versions the same options sit under System Preferences > Sharing. Source: Apple Support, Change the computer name on Mac.

Change the hostname in Terminal with scutil

Terminal changes all three names and works the same on a MacBook, iMac or Mac mini. You need an administrator account.

sudo scutil --set ComputerName "Finance-MBP-01"
sudo scutil --set LocalHostName "Finance-MBP-01"
sudo scutil --set HostName "Finance-MBP-01"

Then flush the DNS cache so the new name is picked up:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Close the Terminal window and open a new one. The prompt reads the name when the shell starts, so an open window keeps showing the old one.

Check the result

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

If scutil --get HostName prints HostName: not set, no explicit hostname exists and macOS builds one from other sources. Setting it with the command above fixes that.

Why Terminal still shows a different name

  • Old window. The prompt does not update in a window that was already open. Open a new window.
  • HostName comes from the network. If no HostName is set, the Mac can take a name from DHCP or reverse DNS on the network it joins, so the name changes between the office and home. Set HostName explicitly to stop that.
  • Different name in a different place. Finder and AirDrop show ComputerName. The router and other Macs show LocalHostName. Change all three to the same value.
  • The name has a number on the end. Another device on the network uses the name already, so macOS appended -2. Pick a unique name.

Name Macs consistently across a fleet

A name tells you something only if every Mac follows the same pattern. A few rules that hold up:

  • Keep names short and ASCII, with hyphens and no spaces, so all three names can be identical.
  • Put something stable in the name. The serial number never changes. A person's name does, and then the name is wrong.
  • Do not put the user's full name in it. Hostnames show up on the network and in logs.
  • Decide the pattern before you enroll devices, so the console and your inventory match from day one.

Rename many Macs with a script

For a fleet, use the serial number as the name. This script reads it, sets all three names and flushes the cache. It needs to run as root, so run it with sudo.

#!/bin/bash
serial=$(ioreg -l | awk -F'"' '/IOPlatformSerialNumber/{print $4}')
name="MAC-${serial}"
/usr/sbin/scutil --set ComputerName "$name"
/usr/sbin/scutil --set LocalHostName "$name"
/usr/sbin/scutil --set HostName "$name"
/usr/bin/dscacheutil -flushcache
/usr/bin/killall -HUP mDNSResponder

Test it on one Mac first and confirm with scutil --get afterwards. A serial number contains only letters and numbers, so it is safe for the local hostname.

If you only need a different account name or home folder, that is a separate job: see how to change the user name and home folder on a Mac and how to change the administrator name on a MacBook.

Managing this across many devices

Renaming one Mac takes a minute. Renaming a hundred is a job for a script. trio.so runs scripts on enrolled Macs from the console. A script on macOS runs when you start it. See Apple device management.

The trio.so Create script wizard with a bash script that renames a Mac using scutil.
In trio.so, IT creates a script for enrolled Macs from the Create script wizard.

Ready-to-use Templates

Must-have Template Toolkit for IT Admins

Explore All
Template Toolkit

Run scripts on your Macs from one console

trio.so runs scripts on enrolled Macs from the console.

Start free trial

Get Ahead of the Curve

Every organization today needs a solution to automate time-consuming tasks and strengthen security. Without the right tools, manual processes drain resources and leave gaps in protection. trio.so is designed to solve this problem, automating key tasks, boosting security, and ensuring compliance with ease.

Don't let inefficiencies hold you back.

Every organization today needs a solution to automate time-consuming tasks and strengthen security. Without the right tools, manual processes drain resources and leave gaps in protection. trio.so is designed to solve this problem, automating key tasks, boosting security, and ensuring compliance with ease.

Smiling womanAbstract geometric patternAbstract geometric patternSmiling womanSmiling woman

Frequently Asked Questions (FAQ)

Have questions? We've got answers. This section covers some of the most commonly asked questions related to this topic.

Open System Settings > General > About and edit the Name field. For the shell hostname as well, run sudo scutil --set HostName "NewName" in Terminal, then open a new Terminal window.

Run sudo scutil --set ComputerName "NewName", sudo scutil --set LocalHostName "NewName" and sudo scutil --set HostName "NewName". Use only letters, numbers and hyphens in the last two.

ComputerName is the friendly name in Finder and AirDrop. LocalHostName is the Bonjour name ending in .local. HostName is the name the shell and DNS tools use.

The prompt reads HostName when the window opens, and HostName can come from your network if you never set it. Set it with scutil and open a new window.

Only in the computer name. LocalHostName and HostName should have no spaces. macOS replaces spaces with hyphens in the local hostname.

Related

From the blog

The related industry news, interviews, technologies, and resources.