Skip to content

Setting the Hostname

pkgdemon edited this page Aug 28, 2026 · 2 revisions

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.

How the name is chosen

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.

Setting the hostname

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.plist

Then 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.plist

Confirm it took:

hostname                       # nextbsd
sysctl kern.hostname           # kern.hostname: nextbsd

The change is persistent — hostnamed reads the same file on every boot.

About that nesting

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).

Reverting to the default

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.plist

Two things to expect

Your 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 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.

See also

Clone this wiki locally