Change Mac Hostname via Terminal
In this article
Yes, you can change your Mac's hostname directly from the Terminal using the scutil command. This guide shows you the exact commands to set your computer's name, which is visible on your local network and in the sharing preferences.
Understanding Hostnames on macOS
macOS uses three separate names that are often confused:
- Computer Name – The friendly name shown in Finder, Sharing preferences, and to other devices on your local network (e.g., "My MacBook Pro").
- Local Hostname – The Bonjour name used for network discovery, ending in
.local(e.g.,My-MacBook-Pro.local). It's derived from the Computer Name, with spaces replaced by hyphens. - Hostname – The fully qualified domain name (FQDN) used by the system and terminal commands like
hostname. It may be the same as the Local Hostname or a different value set by your network.
Changing one does not automatically change the others, which is why it's important to know which one you're targeting.
Why Change Your Hostname?
You might want to change your hostname for several reasons:
- To make your Mac easily identifiable on a network with many devices.
- To avoid conflicts when two Macs have the same default name (like "MacBook Pro").
- To set a consistent name for SSH, file sharing, or remote access.
- To reflect a new owner or purpose for the machine.
How to View Your Current Hostnames
Open Terminal (found in Applications > Utilities) and run:
scutil --get ComputerName
scutil --get LocalHostName
scutil --get HostNameEach command returns the current value. If a name isn't set, you'll see an error like SystemConfigurationGet... failed.
Changing the Hostnames via Terminal
Use the scutil command with the --set flag to change each name. You'll need administrator privileges, so prefix with sudo and enter your password when prompted.
Set the Computer Name
sudo scutil --set ComputerName "MyNewName"This is the name shown in Finder and to other devices on your network. It can contain spaces and special characters.
Set the Local Hostname
sudo scutil --set LocalHostName "MyNewName"This sets the Bonjour name (without the .local suffix). Use only letters, numbers, and hyphens; spaces are not allowed. The system will automatically append .local.
Set the Hostname
sudo scutil --set HostName "MyNewName.local"This sets the FQDN. It's often set to the same as the Local Hostname with .local added, but you can use any valid hostname. If you're not sure, you can leave it blank (the system will use the Local Hostname).
Verifying the Changes
After running the commands, verify with:
scutil --get ComputerName
scutil --get LocalHostName
scutil --get HostNameYou can also check the terminal prompt – it should update to reflect the new hostname. Additionally, open System Settings > General > Sharing to see the updated Computer Name.
Alternative Method: System Settings
If you prefer a graphical interface, you can change the Computer Name and Local Hostname via System Settings > General > Sharing. Click the edit button (pencil icon) next to the name. The Local Hostname updates automatically when you change the Computer Name, unless you've manually set it separately.
The Terminal method gives you more control and is faster for scripting or remote management.
Common Issues and Troubleshooting
- Name doesn't appear on network immediately: It can take a few minutes for Bonjour to propagate. Try restarting your Mac or toggling Wi-Fi.
- Terminal shows old hostname: Close and reopen Terminal, or run
hostnameto see the current value. - Permission denied: Ensure you use
sudoand type your password correctly. - Local Hostname with spaces: Spaces are not allowed; use hyphens instead. The system will replace spaces with hyphens automatically if you set the Computer Name.
Frequently Asked Questions
Does changing the hostname affect my files or apps?
No, it only affects the network name. Your files, settings, and applications remain untouched.
Will I lose my hostname after a macOS update?
Usually not, but major updates can occasionally reset network settings. You can easily reapply the commands.
Can I set the hostname to any string?
For the Local Hostname, stick to letters, numbers, and hyphens. For the Computer Name, you can use spaces and most punctuation. The Hostname should follow standard DNS rules (letters, numbers, hyphens, periods).
What's the difference between LocalHostName and HostName?
LocalHostName is used for Bonjour (local network discovery) and ends with .local. HostName is the system's FQDN, which can be used for external connections. They can be different.
Do I need to restart after changing the hostname?
Not necessarily, but a restart ensures all services pick up the new name. If you don't want to restart, try logging out and back in.