Skip to content

Instantly share code, notes, and snippets.

@a1ip
Last active March 18, 2024 00:01
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a1ip/68db7b4e137d958da58e587a3a44dab8 to your computer and use it in GitHub Desktop.
Save a1ip/68db7b4e137d958da58e587a3a44dab8 to your computer and use it in GitHub Desktop.
How to set the Mac hostname or computer name from the terminal

How to set the Mac hostname or computer name from the terminal

  1. Open a terminal.
  2. Type the following command to change the primary hostname of your Mac: This is your fully qualified hostname, for example myMac.domain.com
sudo scutil --set HostName <new host name>
  1. Type the following command to change the Bonjour hostname of your Mac: This is the name usable on the local network, for example myMac.local.
sudo scutil --set LocalHostName <new host name>
  1. If you also want to change the computer name, type the following command: This is the user-friendly computer name you see in Finder, for example myMac.
sudo scutil --set ComputerName <new name>
  1. Flush the DNS cache by typing:
dscacheutil -flushcache
  1. Restart your Mac.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment