You can change your Mac computer name from Terminal by updating the device name shown to Bonjour and other network services, which is helpful when the default name is generic or unsuitable for your environment. This process edits the ComputerName field used by macOS for display, while HostName and LocalHostName are handled separately and may need distinct commands. Before you begin, back up important data and confirm you have admin privileges on the account running sudo, because these commands write system settings that affect network visibility and access. The following explains exactly how to change mac name in terminal, what each name field means, and how to verify changes.
Understanding macOS Name Fields
macOS uses several related but distinct name fields that affect how your Mac appears on networks and to other services. These fields are not always synchronized, so it is important to know which one you are changing and what it controls.
ComputerName
ComputerName is the user-friendly name shown in Finder, Sharing preferences, and many GUI prompts. This is often the value users want to change when they refer to the computer name. You can view it by opening System Settings, going to General, and looking at the Name field, or by running scutil --get ComputerName in Terminal.
HostName
HostName is the name used primarily by command-line tools and networking utilities, and it typically maps to the short hostname on the network. It can be set to a different value than ComputerName, and you can read it with scutil --get HostName or the hostname command.
LocalHostName
LocalHostName is the Bonjour name that macOS advertises on your local network with a .local suffix, such as macbook.local. It is derived from the HostName by default and is used for discovery protocols like mDNS. You can see it by running scutil --get LocalHostName.
When you change mac name in terminal, you can target any of these fields depending on your goal, and it is important to specify the correct one so that tools and services see the name you intend.
Permanent Method: Using scutil
The recommended way to change the ComputerName that is visible in macOS UI and used by many services is to use scutil with sudo. This method writes the setting persistently so it survives restarts.
To change the ComputerName, use the following command syntax, replacing MyMac with the exact name you want. If your desired name includes spaces, wrap it in quotes.
sudo scutil --set ComputerName "MyMac"
After running this, the change applies immediately for GUI tools and network queries that read ComputerName. You can confirm it took effect by running scutil --get ComputerName, which should return the new value.
Example Workflow
Below is a concise, non-exhaustive example workflow illustrating typical commands and expected outcomes when changing the Mac name from Terminal.
| Command | Result | Purpose |
|---|---|---|
scutil --get ComputerName |
OldName | Check current ComputerName |
sudo scutil --set ComputerName "Office Mac" |
(no output) | Set new ComputerName |
scutil --get ComputerName |
Office Mac | Verify the change |
sudo scutil --set HostName office-mac |
(no output) | Set HostName for CLI use |
sudo dscacheutil -flushcache
| (no output) | Refresh local name caches if needed |
Changing HostName and LocalHostName
Although many users focus on ComputerName, you may also need to change HostName or LocalHostName for scripting, SSH, or Bonjour reasons. Use separate commands for each field to avoid confusion.
Setting HostName from Terminal
To set the HostName, which affects command-line tools and some network scripts, use the following command. Note that sudo is required for persistence across reboots.
sudo scutil --set HostName new-hostname
You can confirm the HostName with scutil --get HostName or the standard hostname command. If you only change HostName but not ComputerName, the Finder and user-facing displays may retain the previous ComputerName, which is expected behavior.
Setting LocalHostName for Bonjour
LocalHostName controls the .local name advertised via Bonjour, and by default it is derived from HostName. To change it directly, use this command, replacing mymac with a name that uses only lowercase letters, numbers, and hyphens, because Bonjour names are limited in characters.
sudo scutil --set LocalHostName mymac
After changing LocalHostName, you may need to flush the cache for name-resolution tools to pick up the new value. On Apple Silicon and Intel Macs running supported versions of macOS, you can flush the cache with the following command.
sudo dscacheutil -flushcache
With these commands, you can change the Bonjour name of Mac in terminal and ensure that mymac.local resolves correctly within your local network.
Verification and Scope
After you change mac name in terminal, you should verify which fields were updated and how services on your network see the machine. The changes you make with scutil are stored in the dynamic store and persist across reboots, but some applications may cache old names or rely on different fields.
Use these commands to review all three main fields at once.
scutil --get ComputerName
scutil --get HostName
scutil --get LocalHostName
You can also test network visibility by using tools such as dscacheutil and browsing to the .local address if Bonjour is working in your environment. Note that managed environments, such as enterprise networks or systems with MDM, may enforce naming policies that override local settings, which is an important exception to keep in mind.
Troubleshooting and Best Practices
If the name does not appear to change as expected, check whether you are editing the correct field and confirm that no management profiles are enforcing a different value. Flushing the cache with sudo dscacheutil -flushcache can help resolve stale lookups, especially for .local Bonjour names. Always use exact spelling and quotes around names with spaces, and remember that HostName and LocalHostName have different character restrictions than ComputerName.
For routine use, changing the ComputerName through System Settings is often simpler, but using terminal is faster for scripting, remote administration, or when GUI access is unavailable. Because the commands write to the system store directly, they are durable across restarts and do not require third-party tools.
Summary
To change your Mac name from Terminal, use sudo scutil --set ComputerName "Desired Name" for the user-facing computer name, and optionally adjust HostName and LocalHostName for command-line and Bonjour behavior. Verify each field with scutil --get variants, flush caches if necessary, and be aware that managed environments may enforce centralized naming. These steps provide a reliable, permanent method to update how your Mac identifies itself on the network.