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.
Change the computer name
1 2 |
#!/bin/bash scutil --set ComputerName $ComputerName |
Change the local host name
1 2 |
#!/bin/bash scutil --set LocalHostName $LocalHostName |
Change the Hostname
1 2 3 |
#!/bin/bash # The primary hostname of your Mac, for example Your-iMac.domain.com scutil --set HostName $HostName |
It is advised to empty the DNS Cache after making changes to your network settings to avoid connectivity issues.
1 2 |
#Flush the DNS cache sudo dscacheutil –flushcache |
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.