Category filter

Script to rename Mac

A Mac device can be identified using the computer name or the local hostname. A Mac’s computer name is displayed on top of the Sharing preferences pane, and the local hostname is displayed right below the computer name. By default, the local hostname of your device is your computer name with “.local” added to the end, and all the spaces are replaced by hyphens. The Hostname is displayed in the default terminal command prompt (user@hostname).

This document guides you on how to change the computer name, local host name, and hostname of a macOS device using Hexnode’s Custom Script feature.

Disclaimer:

The Sample Scripts provided below are adapted from third-party Open-Source sites.

Change the computer name

Sharing pane in macOS System preferences with Computer Name and Local Hostname.

Change the local host name

Change the Hostname

macOS terminal with Hostname

It is advised to empty the DNS Cache after making changes to your network settings to avoid connectivity issues.

You could restart your Mac if the changes are not reflected on your device.

sudo (“super user do”) allows a system administrator to delegate authority to give certain users (or groups of users) the ability to run some (or all) commands as root or another user.

scutil – The scutil command (“system configuration utility”) can display basic network information, set the computer hostname, change the computer name, check if another host is reachable from your Mac or view technical DNS information.

dscacheutil – Directory Service cache to gather information, statistics, initiate queries and flush the cache.

flushcache – Flush the entire cache. This should only be used in extreme cases. Validated information is used within the cache along with other techniques to ensure the OS has valid information available to it.

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository