Best-practices for naming hosts
(from AskDifferent: Set the hostname/computer name for macOS
and AutoDesk's Support doc.: How to set the Mac hostname or computer name from the terminal)
- Choose a Valid Hostname
- Check the Current Hostname
- Set a New Hostname
- Optional: Assign a Loopback Address to the Hostname
- Reboot
- Check the (New) Hostname
- Use
a-z,A-Z,0-9, and hyphen (-) characters only - Avoid underscores (
_), spaces, and other symbols - Do not start a host-name with a number
- Do not end a host-name with a hyphen
To list the existing name(s) of this machine
open a Terminal window and run the following commands
scutil --get HostName
scutil --get LocalHostName
scutil --get ComputerNameTo change the hostname of this machine
open a Terminal window and run the following commands
NEW_HOSTNAME=<New-Name>
sudo scutil --set HostName $NEW_HOSTNAME
sudo scutil --set LocalHostName $NEW_HOSTNAME
sudo scutil --set ComputerName $NEW_HOSTNAME
dscacheutil -flushcacheTo ensure that the DNS domain name and FQDN of the machine are reported back correctly,
change the following line of the /etc/hosts file to include the FQDN and host-name as
the first two entries:
127.0.0.1 hostname-fqdn hostname localhost
For example:
127.0.0.1 my-server.example.com my-server localhost
Remove any other references to hostname-fqdn or hostname from other entries in the file.
Reboot the server so the changes will take effect,
for example:
sudo rebootSee above - Check the Current Hostname