Print or Set (temporarily) the name of current host system.
Syntax hostname [-fs] [name-of-host] Key -f Include domain information in the printed name. This is the default behavior. -s Trim off any domain information from the printed name.
The super-user can set the hostname by supplying a hostname argument.
When you open a new Terminal window, the prompt will begin with the hostname and this may appear differently if you are connected to a WiFi network compared to opening a new Terminal when disconnected.
A DHCP server can provide a hostname to a client, along with an IP address, and the client system hostname will be changed to whatever the DHCP server sends.
If a NetBIOSName has been configured, (it is typically set to = the hostname) the value is stored in a preference file:
$ defaults read /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName
You can set the NetBIOS name with defaults or in System Preferences ➞ Network ➞ active network port ➞ Advanced ➞ WINS tab.
To keep the hostname between reboots, run scutil --set HostName name-of-host.
Display the current hostname:
$ hostname
ss64.local
The hostname is also stored in a system variable named HOSTNAME:
$ echo $HOSTNAME
ss64.local
Set a new hostname:
$ sudo hostname FancyNewName
$ scutil --set HostName FancyNewName
“ One thing you don't want to do as a host is be running around all evening. Do as much as you can ahead of time, so all you have to do is grill the main ingredients” ~ Bobby Flay
scutil - Manage system configuration parameters, including hostname.
dscacheutil -flushcache