Command: hostname
Get or set the system's various hostnames.
Usage
Usage: m hostname [OPTION] [newhostname]
Description: Manage the hostname of the system. This includes ComputerName, HostName, LocalHostName, and NetBIOSName.
Options:
--help Show this help message and exit
Description
On macOS, there are several different names for the computer used in different contexts:
- ComputerName: The user-friendly name shown in Finder.
- HostName: The name used by command-line tools and for network identification.
- LocalHostName: The name used for Bonjour/mDNS services (e.g.,
My-Mac.local
). - NetBIOSName: The name used for Windows file sharing (SMB).
This command gets or sets all of them simultaneously.
Examples
Get Current Hostnames
Run the command without any arguments to display the current names.
m hostname
# Sample Output:
# ComputerName: My-Mac
# HostName: My-Mac
# LocalHostName: My-Mac
# NetBIOSName: MY-MAC
Set New Hostname
Provide a new name as an argument to update all hostname values. This requires sudo
privileges.
sudo m hostname New-Mac-Pro
# Output:
# Hostname changed to: New-Mac-Pro