Unset HostName (after scutil used to set)

donmontalvo
Esteemed Contributor III

The scutil doesn't appear to have a reliable way to undo HostName that was set.

man scutil seems to indicate putting no value in the command will undo it, but doesn't seem to work.

--set pref [newval]
         Updates the specified preference with the new value.  If the new value is not specified on the com-
         mand line then it will be read from standard input.

         Supported preferences include: ComputerName LocalHostName HostName

         The --set option requires super-user access.

What's the magic pill to undo HostName?

--
https://donmontalvo.com
13 REPLIES 13

nessts
Valued Contributor II

why would you want to do that? Out of curiosity.

donmontalvo
Esteemed Contributor III

To be clear, we never set HostName. We discovered it is set on some Macs. Trying to remove the setting.

Look through old threads, I've always been like "Why are you doing that?!" so we are on the same page. ;)

Cleaning up.

--
https://donmontalvo.com

jonscott
New Contributor

I seem to recall using

scutil --set HostName ""

in the past, though I could be wrong...

donmontalvo
Esteemed Contributor III

Yep, tried that...it sets hostname to:

""

Haha

--
https://donmontalvo.com

jonscott
New Contributor

Nice :) how about removing the HostName key from /Library/Preferences/SystemConfiguration/preferences.plist?

chriscollins
Valued Contributor

You must be doing something weird because when I set it to "" it goes back to "not set". I blame you Don ;)

Though if you really want to blow it away you could edit the /Library/Preferences/SystemConfig/preferences.plist file. Or just throw it away and restart. It will set your computer name to local host and remove the other versions of the host name.

Edit: Must have been typing at same time :)

brock_walters
Contributor

here are my results:

b...$ scutil --set HostName ""
b...$ scutil --get HostName
HostName: not set

donmontalvo
Esteemed Contributor III

Thanks for all the feedback. I tested on 10 more Macs, and 4 had the problem, but 6 didn't.

I'll have to sift through our policies/mcx/configprofiles to see if something is doing this.

Here is the sanitized output from one of the effected Macs.

MyComputer:~ myshortname$ scutil --get HostName
MyComputer
MyComputer:~ myshortname$ sudo scutil --set HostName
Password:
HostName [MyComputer]: ""
MyComputer:~ myshortname$ scutil --get HostName
""
MyComputer:~ myshortname$
--
https://donmontalvo.com

bradtchapman
Valued Contributor II

I tested this on OS X 10.10 "Vegemite" and OS X 10.11, "El Capitan & Tennille."

Manually setting the hostname to "1234" on both machines did exactly what it should. The Computer Name and LocalHostName were unaffected. Setting it back to "" on both machines resulted in "Host Name: Not Set."

@donmontalvo,

  1. Are these machines under management by Casper?
  2. Are there any profiles in System Preferences?
  3. Are there any managed preferences in /Library/Managed Preferences/ ?
  4. Are these machines fresh installs or migrations?

donmontalvo
Esteemed Contributor III

@jonscott and @chriscollins thanks we're hoping to avoid editing that file. I'll have a look at the areas I mentioned to see if it's being set somewhere.

--
https://donmontalvo.com

donmontalvo
Esteemed Contributor III

Hi @bradtchapman,

In response to #4 on your post (the rest has already been hashed out), we sampled a mix of both. So as we mentioned already in the thread, we're going to have a look at those areas. It looks like something is being set somewhere.

There is also a chance someone pushed out a command to set HostName because Google told them to so it. We've seen this is a fair number of large environments.

Underscores the importance of having a programmatic/modular approach, rather than creating a monolithic/baked-in environment mess.

f2595a733b9743c2862167661fb509a4

--
https://donmontalvo.com

russeller
Contributor III

+1 for @donmontalvo high res Picard.

sean
Valued Contributor

It's how you are using the command, the interactive escapes the quotes.

ml0637:/ root# scutil --get HostName
HostName: not set
ml0637:/ root# scutil --set HostName ML0637
ml0637:/ root# scutil --get HostName
ML0637
ml0637:/ root# scutil --set HostName       
HostName [ML0637]: ""
ml0637:/ root# scutil --get HostName
""
ml0637:/ root# scutil --set HostName ""
ml0637:/ root# scutil --get HostName
HostName: not set
ml0637:/ root# scutil --set HostName """"
ml0637:/ root# scutil --get HostName
""
ml0637:/ root# scutil --set HostName ""
ml0637:/ root# scutil --get HostName
HostName: not set