From: Greg Ercolano <erco@(email surpressed)>
Subject: [OSX/ADMIN] Setting the hostname from the command line
   Date: Thu, 12 Mar 2015 23:37:50 -0400
Msg# 2389
View Complete Thread (1 article) | All Threads
Last Next
> On OSX Yosemite, the /etc/hostconfig file no longer exists.
> We used to put HOSTNAME=xxx in this file and that worked,
> but now with the file gone, we're left with the System Preferences
> Sharing > Computer Name field, which seems to not give consistent results.
>
> How do we set the hostname so that it 'sticks'?

	This comes up a lot, esp. now that the /etc/hostconfig file is
	no longer being supported in OSX 10.10 Yosemite.

	The short answer is you should now use these three commands:

            sudo scutil --set ComputerName  "newname"
            sudo scutil --set LocalHostName "newname"
            sudo scutil --set HostName      "newname"

        Yes, the machine has three hostnames :/
        According to the scutil(8) man page, these are respectively:

               ComputerName   The user-friendly name for the system.

               LocalHostName  The local (Bonjour) host name.

               HostName       The name associated with hostname(1) and
                              gethostname(3).

        That last one is what Rush and other unix tools are interested in.
        The others are for Finder browsing and whatnot. I usually set all three
	to the same thing.

        So if the machine is to be named "tahoe", I use:

            sudo scutil --set ComputerName  "tahoe"
            sudo scutil --set LocalHostName "tahoe"
            sudo scutil --set HostName      "tahoe"
	
        This sticks through reboots.

	This works well for machines with domain names too; the short name
	will be used, and you can use the Name Server / Search Domain fields
	in System Prefs -> Networking -> (network interface) -> Advanced
	to configure the client DNS settings.

        I would suggest once setting the hostname this way, you do not
        mess with the System Prefs -> Sharing -> Computer Name: anymore,
	and stick with the command line approach.

-- 
Greg Ercolano, erco@(email surpressed)
Seriss Corporation
Rush Render Queue, http://seriss.com/rush/


Last Next