MacOS
View all Worklets
MacOSmacOS

Change Hostname to Serial Number

Set macOS hostname, LocalHostName, and ComputerName to match the hardware serial number

Worklet Details

What the Hostname-to-Serial Worklet does

This Automox Worklet™ configures three macOS naming properties to match the hardware serial number: HostName (the network hostname), LocalHostName (the Bonjour name), and ComputerName (the user-friendly name shown in Finder and System Preferences). The Worklet retrieves the serial number using ioreg to query the IOPlatformSerialNumber property.

After setting the names, the Worklet flushes the DNS cache to apply the changes immediately. This approach provides a unique, hardware-based identifier that remains consistent even if the endpoint is reimaged or reassigned to a different user.

Why standardize hostnames to serial numbers

macOS endpoints with generic or user-configured hostnames like MacBook-Pro or Johns-MacBook create inventory management challenges. IT operations teams cannot reliably identify specific endpoints from network logs, asset tracking systems, or security event data when hostnames are not standardized. This makes it difficult to track down compromised endpoints or locate specific endpoints for maintenance.

Serial number-based hostnames provide unique, permanent identifiers that do not change when endpoints are reassigned between users. Asset management systems, MDM platforms, and security tools can correlate endpoint data across multiple systems using the serial number as a reliable key. This standardization reduces asset tracking errors and improves operational efficiency.

Organizations managing large macOS fleets benefit from automated hostname standardization. Manual hostname configuration does not scale across hundreds or thousands of endpoints. This Worklet automates the process of setting hostnames to serial numbers, maintaining consistency across your entire fleet without manual IT intervention.

How hostname configuration works

  1. Evaluation phase: The Worklet retrieves the hardware serial number using ioreg and compares it against the current HostName, LocalHostName, and ComputerName values using scutil --get. If any of the three names do not match the serial number, the endpoint is flagged for remediation.

  2. Remediation phase: The Worklet sets each mismatched name to the serial number using scutil --set commands. After updating all three names, the Worklet flushes the DNS cache using dscacheutil -flushcache to apply the changes without requiring a restart.

Hostname configuration requirements

  • macOS endpoint (workstation or server)

  • Validated on macOS Monterey, Big Sur, and Apple Silicon (M1) systems

  • Administrative privileges (provided by the Automox Agent)

Expected hostname configuration

After remediation, the endpoint's hostname, local hostname, and computer name are all set to the endpoint's serial number. This change persists across reboots and system updates. Network services and the endpoint's identity in logs and management platforms reflect the serial number-based hostname.

The Worklet verifies the hostname change through its evaluation phase. You can confirm the configuration by checking System Preferences under Sharing, using the hostname command in Terminal, or reviewing Worklet execution results in the Automox console showing the serial number-based hostname is active.

How to validate change hostname to serial number changes

  1. Run this Worklet on a pilot macOS endpoint and review evaluation output for change hostname to serial number.

  2. Confirm Automox activity logs show successful completion and exit code 0.

  3. Verify endpoint state using checks aligned to evaluation script logic, such as exit.

  4. Validate remediation effects from script operations such as scutil, dscacheutil, exit, then rerun evaluation for compliance.

View in app
evalutation image
remediation image

Consider Worklets your easy button

What's a Worklet?

A Worklet is an automation script, written in Bash or PowerShell, designed for seamless execution on endpoints – at scale – within the Automox platform. Worklet automation scripts perform configuration, remediation, and the installation or removal of applications and settings across Windows, macOS, and Linux.

do more with worklets