Hostname, Computer name, and Local Hostname

Mbentley777
Contributor

When I image it seems as though only the computer name is getting set when I name a machine using the prompt in Casper Imaging.

I'm not sure if this is the expected behavior - but -my- expected behavior (maybe a bit misguided) is that it would not only set the Computer Name, but the hostname and the local hostname to match.

Am I way off here?

2 ACCEPTED SOLUTIONS

Cem
Valued Contributor

something like this perhaps...

# set the computer name
setName=networksetup -getcomputername
scutil --set ComputerName ${setName}
scutil --set LocalHostName ${setName}
scutil --set HostName ${setName}

View solution in original post

Mbentley777
Contributor
#!/bin/sh

hostname=`jamf getComputerName | cut -c 16-34`
localhostname=`jamf getComputerName | cut -c 16-26`

echo "FQDN hostname will be set to $hostname"
echo "Local hostname will be set to $localhostname"

/usr/sbin/scutil --set HostName $hostname
/usr/sbin/scutil --set LocalHostName $localhostname

exit=0

View solution in original post

12 REPLIES 12

ernstcs
Contributor III

Can you please state what version of the OS you're trying to image and what version of the JSS you're on?

Mbentley777
Contributor

Absolutely - sorry for the omission.

  • 8.6
  • 10.7.4
  • Image based on Composer snapshot of 10.7.4

alexjdale
Valued Contributor III

I ran into so many issues with this in the past due to Apple's auto-naming that I explicitly set all three to be the same, using scutil.

nkalister
Valued Contributor

yeah, I do the same as alex. scutil in a script for the win on this one.

Mbentley777
Contributor

Sounds like a plan - since I've already got the computer name set correctly - do you guys just get the computer name and then set it as a variable (computername) in the script and run scutil --set HostName $computername ?

mm2270
Legendary Contributor III

The 3 possible names that a Mac can have is one of the things I often get ribbed about by my fellow Windows colleague. They find it ridiculous that there can be 3 possible names, potentially all different in certain circumstances. I can't say I really blame them. A new OOB Mac setup sets all these the same, but in an imaging or managed environment they can get out of sync unless you do the scutil naming commands as mentioned above.

Cem
Valued Contributor

something like this perhaps...

# set the computer name
setName=networksetup -getcomputername
scutil --set ComputerName ${setName}
scutil --set LocalHostName ${setName}
scutil --set HostName ${setName}

Mbentley777
Contributor
#!/bin/sh

hostname=`jamf getComputerName | cut -c 16-34`
localhostname=`jamf getComputerName | cut -c 16-26`

echo "FQDN hostname will be set to $hostname"
echo "Local hostname will be set to $localhostname"

/usr/sbin/scutil --set HostName $hostname
/usr/sbin/scutil --set LocalHostName $localhostname

exit=0

bentoms
Release Candidate Programs Tester

So does

sudo jamf -setComputerName <some name or action>

Not work?

ernstcs
Contributor III

Not if the JSS's record has already been hosed up.

jhbush
Valued Contributor II

I use this ```
scutil --set HostName $(scutil --get LocalHostName)
``` as part of my first boot script. I also write the name out to a file in case I need to change it back if a user renames it something non-standard.

donmontalvo
Esteemed Contributor III

The $HostName attribute has always been a PITA for us, as it uses whatever DNS thinks it should be.

Not saying Microsoft is playing a cruel joke on the Mac community, but I really wish DNS could play nice with Macs...a good start would be to enableScavenge Stale Records by default in DNS...

http://technet.microsoft.com/en-us/library/cc959277.aspx

</rant>

--
https://donmontalvo.com