macOS utilizes three distinct system variables to determine its identity:
By default, the HostName variable is explicitly left undefined in macOS. When undefined, the operating system will attempt to dynamically resolve its own hostname by querying reverse DNS or DHCP information from the primary active network interface.
When a user connects to a modern VPN or proxy service (Zscaler, GlobalProtect, etc), a new virtual network interface is established and prioritized. If the DNS resolution on this new virtual interface returns an IP address, a stale DNS record, or no record at all, the macOS system dynamically updates its own HostName to match this transient state.
The Agent relies on system APIs (like gethostname() ) to identify the endpoint. When reading this newly altered, transient HostName, and depending on the timing of the network transition, the Agent will either overwrite its existing Console record with the incorrect name, or trigger a completely new registration, resulting in a duplicate.
To prevent macOS from dynamically changing its hostname during network transitions, configure the endpoint to use a statically defined HostName using one of the methods below
sudo scutil --get ComputerName
sudo scutil --get LocalHostName
sudo scutil --get HostName
sudo scutil --set HostName <LocalHostName.local>
sudo dscacheutil -flushcache
The following example script is a best effort example and should be adjusted to meet environmental needs accordingly.
#!/bin/bash
# Get LocalHostName
LHN=$(scutil --get LocalHostName)
# If LocalHostName is not blank, change HostName
if [ -n "$LHN" ]; then
scutil --set HostName "$LHN.local"
fi