-
Notifications
You must be signed in to change notification settings - Fork 6
Setting the Hostname
NextBSD has no hostname= line in rc.conf — there is no rc.conf at all.
The hostname is decided at every boot by hostnamed, a launchd daemon that ports
Apple's hostname logic, and you override it by writing one preferences file under
/Local/Library.
hostnamed runs com.apple.hostnamed under launchd and walks a fixed chain,
stopping at the first tier that yields a name:
| # | Tier | Source |
|---|---|---|
| 1 | System preferences |
ComputerName in /Local/Library/Preferences/SystemConfiguration/preferences.plist
|
| 2 | DHCP | Option 12 (host name) from the primary service's lease |
| 3 | Reverse DNS | The PTR record for the primary IP address |
| 4 | Bonjour | The mDNS LocalHostName
|
| 5 | Synthesised | A slug derived from the machine's identity, e.g. virt-10-0
|
A fresh install has no preferences file, so an unconfigured machine lands on tier 2, 3 or 5 — which is why a VM often boots with a name nobody chose. Setting tier 1 wins unconditionally and is the supported way to pick your own.
Suppose you want the machine to be called nextbsd. Create the preferences
directory and write the file:
mkdir -p /Local/Library/Preferences/SystemConfiguration
cat > /Local/Library/Preferences/SystemConfiguration/preferences.plist <<'PLIST'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>System</key>
<dict>
<key>System</key>
<dict>
<key>ComputerName</key>
<string>nextbsd</string>
<key>ComputerNameEncoding</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
PLIST
chmod 644 /Local/Library/Preferences/SystemConfiguration/preferences.plistThen restart hostnamed so it re-reads the file:
launchctl unload /System/Library/LaunchDaemons/com.apple.hostnamed.plist
launchctl load /System/Library/LaunchDaemons/com.apple.hostnamed.plistConfirm it took:
hostname # nextbsd
sysctl kern.hostname # kern.hostname: nextbsdThe change is persistent — hostnamed reads the same file on every boot.
(With one caveat about the first few seconds of boot; see below.)
The doubled System key is not a typo. Preferences are addressed by path, and
the hostname lives at the path /System/System, which on disk is a System
dictionary inside a System dictionary. ComputerNameEncoding is 0, the value
of kCFStringEncodingUTF8.
This is the same on-disk layout macOS uses, so a preferences.plist written by
scutil on a Mac has exactly this shape — only the directory differs
(/Library/… there, /Local/Library/… here, per
Filesystem Layout).
Remove the file and restart the daemon; the machine falls back down the chain to its DHCP, PTR or synthesised name.
rm /Local/Library/Preferences/SystemConfiguration/preferences.plist
launchctl unload /System/Library/LaunchDaemons/com.apple.hostnamed.plist
launchctl load /System/Library/LaunchDaemons/com.apple.hostnamed.plistYour Bonjour name changes with it. hostnamed publishes the new name to
mDNSResponder as well, so the machine immediately stops answering to
oldname.local and starts answering to nextbsd.local. If you are working over
SSH, your next connection is ssh root@nextbsd — an in-flight session survives,
but reconnecting to the old name will not resolve.
The name is not correct for the first few seconds of a boot. hostnamed
sets a synthesised name (virt-10-0 and the like) before it reads your
preferences file, then corrects itself a few seconds later. The configured name
is what sticks, but anything sampling the hostname very early in boot — the
console getty banner included — may show the synthesised one. Tracked as
nextbsd-userland#66.
The daemon restart is required, not optional. hostnamed picks up preference
changes through a commit notification that only fires when a process writes the
file through the preferences API. Editing the file directly does not fire it, so
the value is read at daemon startup instead. Once
scutil is ported
this becomes a single live command with no restart.
-
Filesystem Layout — why this is
/Local/Library, not/Library -
Service Management with launchd —
launchctl load/unload - Command Reference — the rest of the Darwin-derived tools
-
hostname(1),configd(8),mDNSResponder(8)
NextBSD is pre-production — continuous builds only, no stable release yet. Questions are welcome in Discussions.